-
-
Save TheRealMentor/5eeabfd77116ae61aeb8f25917538c63 to your computer and use it in GitHub Desktop.
Reading Wave File
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
import pyaudio | |
import wave | |
#Defining Chunk | |
chunk = 1024 | |
#Female voice, for male voice file_name = 'brian.wav' | |
file_name = 'amy.wav' | |
#Opening file | |
f = wave.open(file_name,'rb') | |
#Instantiating PyAudio | |
p = pyaudio.PyAudio() | |
stream = p.open(format = p.get_format_from_width(f.getsampwidth()), | |
channels = f.getnchannels(), | |
rate = f.getframerate(), | |
output = True) | |
#Reading data from the file | |
data = f.readframes(chunk) | |
#Finding the Number of Channels and Sampling Rate | |
channels = f.getnchannels() | |
rate = f.getframerate() | |
#Printing the File name, Number of Channels and Sampling rate | |
print 'File:', file_name | |
print 'Channels:', channels | |
print 'Rate:', rate | |
#Playing the voice | |
while data: | |
stream.write(data) | |
data = f.readframes(chunk) | |
#Stopping the voice | |
stream.stop_stream() | |
stream.close() | |
#Terminating the PyAudio | |
p.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment