-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoice_recorder.py
45 lines (35 loc) · 969 Bytes
/
Voice_recorder.py
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
from email.mime import audio
from tracemalloc import start
import pyaudio
import wave
Frames_Per_Buffer = 3200
Format = pyaudio.paInt16
Channels = 1
Rate = 16000
P = pyaudio.PyAudio()
Recorder = P.open(
format = Format,
channels = Channels,
rate = Rate,
input = True,
frames_per_buffer = Frames_Per_Buffer
)
print('Start Recording')
seconds = 5
track_name = 'Track.wav'
frames = []
def audio():
for i in range(0,int(Rate/Frames_Per_Buffer*seconds)):
Recording = Recorder.read(Frames_Per_Buffer)
frames.append(Recording)
Recorder.stop_stream()
Recorder.close()
P.terminate
audio_track = wave.open(track_name,"wb")
audio_track.setnchannels(Channels)
audio_track.setframerate(Rate)
audio_track.setsampwidth(P.get_sample_size(Format))
audio_track.writeframes(b"".join(frames))
audio_track.close()
print('recorded')
return audio_track