I saved "wav" file with below code.
However, I can't hear any sound from "wav" file.
Is there any solution?
import pyaudio
import wave
from datetime import datetime
print('Pyaudio version: ', pyaudio.__version__)
########################################################################################################
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
print(p.get_device_info_by_index(i).get('name'))
########################################################################################################
form_1 = pyaudio.paInt16
chans = 1
samp_rate = 44100
chunk = 1024
record_secs = 5
num = 1
while True:
audio = pyaudio.PyAudio() # create pyaudio instantiation
# create pyaudio stream
stream = audio.open(format = form_1, rate = samp_rate, channels = chans, \
input = True, input_device_index = 1, frames_per_buffer=chunk)
frames = []
start_time = datetime.now()
# loop through stream and append audio chunks to frame array
for j in range(0, int((samp_rate/chunk)*record_secs)): # 53 | (samp_rate/chunk)*record_secs)*chunk = samp_rate*record_secs
data = stream.read(chunk)
frames.append(data)
end_time = datetime.now()
# stop the stream, close it, and terminate the pyaudio instantiation
stream.stop_stream()
stream.close()
audio.terminate()
# name of .wav file
wav_output_filename = './Record/%d_%s_%s_%s.wav' % (num, start_time.strftime('%Y%m%d'), start_time.strftime('%H%M%S'), end_time.strftime('%H%M%S'))
num+=1
# save the audio frames as .wav file
wavefile = wave.open(wav_output_filename,'wb')
wavefile.setnchannels(chans)
wavefile.setsampwidth(audio.get_sample_size(form_1))
wavefile.setframerate(samp_rate)
wavefile.writeframes(b''.join(frames))
wavefile.close()
My id is blocked from Stackoverflow due to low quality questions.
If someone can ask instead of me for this question to Stackoverflow, then it will be so much appreciated.
I totally tested same code of below code but my wav file doesn't have any sound.