-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRec_2_db.py
More file actions
53 lines (38 loc) · 1.02 KB
/
Copy pathRec_2_db.py
File metadata and controls
53 lines (38 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pyaudio
import numpy as np
import audioop
import math
import itertools
import os
CHUNK = 1024
WIDTH = 2
CHANNELS = 2
FORMAT = pyaudio.paInt16
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,#p.get_format_from_width(WIDTH)
channels=CHANNELS,
rate=RATE,
input=True,#output = True
frames_per_buffer=CHUNK)
db = 0
frames = []
buffer = []
stream.start_stream()
print("* recording")
for x in itertools.repeat(1):
data = stream.read(CHUNK)
frames.append(data)
decoded = np.fromstring(data, 'Float32')
rms = audioop.rms(decoded, 2) # 2 bytes of audio data
print("rms:{}".format(rms))
try:
db = 20 * (math.log(rms,10))
print("db:{}".format(db))
except:
pass
if (db > 74):
os.system('python D:/Python36/rec_2_detect.py') # specify path where rec_2_detect.py is stored in your system
stream.stop_stream()
stream.close()
p.terminate()