-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoicerecorder.py
47 lines (36 loc) · 1.39 KB
/
voicerecorder.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
46
47
import sounddevice as sd
from scipy.io.wavfile import write
import wavio as wv
import soundfile as sf
from colorama import init, Fore, Back, Style
# Sampling frequency
freq = 44100
# Recording duration
duration = 3
init(autoreset=True)
input("\nPRESS ENTER TO RECORD YOUR VOICE...")
print(Style.BRIGHT+ Fore.GREEN + "\nSpeak Now...")
# Start recorder with the given values
# of duration and sample frequency
recording = sd.rec(int(duration * freq),
samplerate=freq, channels=1)
# Record audio for the given number of seconds
sd.wait()
#taking input of speakers name
print(Style.BRIGHT + Fore.GREEN +"\n\nEnter speaker's name : ")
input_label = input()
speaker_name=input_label+".wav"
wv.write(speaker_name, recording, freq, sampwidth=2)
data, samplerate = sf.read(speaker_name)
sf.write(speaker_name, data, samplerate, subtype='PCM_16')
print(Style.BRIGHT + Fore.GREEN +"\nDone.......")
input("\nPRESS ENTER TO PLAY VOICE ... ")
# Extract data and sampling rate from file
data, fs = sf.read(speaker_name, dtype='float32')
sd.play(data, fs)
status = sd.wait() # Wait until file is done playing
ob = sf.SoundFile(speaker_name)
print(Style.BRIGHT + Fore.GREEN +"\n.....Audio Details.....")
print(Style.BRIGHT + Fore.GREEN +'\nSample rate: {}'.format(ob.samplerate))
print(Style.BRIGHT + Fore.GREEN +'Channels: {}'.format(ob.channels))
print(Style.BRIGHT + Fore.GREEN +'Subtype: {}'.format(ob.subtype))