Spaces:
Sleeping
Sleeping
Update text_speech_utils.py
Browse files- text_speech_utils.py +4 -24
text_speech_utils.py
CHANGED
@@ -19,30 +19,10 @@ def say(text):
|
|
19 |
p.join()
|
20 |
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
p = pyaudio.PyAudio()
|
27 |
-
|
28 |
-
stream = p.open(format=pyaudio.paInt16, channels=2, rate=sr,
|
29 |
-
input=True, frames_per_buffer=1024)
|
30 |
-
|
31 |
-
frames = []
|
32 |
-
|
33 |
-
for i in range(0, int(sr / 1024 * sec)):
|
34 |
-
data = stream.read(1024)
|
35 |
-
frames.append(data)
|
36 |
-
|
37 |
-
stream.stop_stream()
|
38 |
-
stream.close()
|
39 |
-
p.terminate()
|
40 |
-
|
41 |
-
with wave.open(filename, 'wb') as wf:
|
42 |
-
wf.setnchannels(2)
|
43 |
-
wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
|
44 |
-
wf.setframerate(sr)
|
45 |
-
wf.writeframes(b''.join(frames))
|
46 |
|
47 |
def record_audio_manual(filename, sr = 44100):
|
48 |
input(" ** Press enter to start recording **")
|
|
|
19 |
p.join()
|
20 |
|
21 |
|
22 |
+
def record_audio(filename, sec, sr = 44100):
|
23 |
+
audio = sd.rec(int(sec * sr), samplerate=sr, channels=2, blocking=False)
|
24 |
+
sd.wait()
|
25 |
+
write(filename, sr, audio)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def record_audio_manual(filename, sr = 44100):
|
28 |
input(" ** Press enter to start recording **")
|