Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from abhisheky1806/patch-2
added feature of audio recording
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sounddevice as sd | ||
from scipy.io.wavfile import write | ||
import wavio as wv | ||
|
||
|
||
from pydub import AudioSegment | ||
from os import path | ||
|
||
|
||
#sampling frequency | ||
freq = 44100 | ||
|
||
#recording duration in seconds | ||
duration = 60 | ||
|
||
#start recorder with given values of duration and frequency | ||
recording = sd.rec(int(duration * freq), samplerate=freq, channels=2) | ||
|
||
sd.wait() | ||
|
||
#save the audio | ||
write("testAudio0.wav", freq, recording) | ||
wv.write("testAudio1.wav", recording, freq, sampwidth=2) | ||
|
||
|
||
# if you want to convert f.wav file in .mp3 | ||
#sound = AudioSegment.from_mp3('testAudio0.wav') | ||
#sound.export('testAudio0.mp3', format="wav") |