play:
import pyaudio
import wave
import time
from tqdm import tqdm
def play_audio(wave_path):
'''
while True:
print('play')
time.sleep(1)
'''
time.sleep(0.1)
CHUNK = 1024
f = wave.open(wave_path, 'rb')
# instantiate PyAudio (1)
p = pyaudio.PyAudio()
# open stream (2)
stream = p.open(format=p.get_format_from_width(f.getsampwidth()),
channels=f.getnchannels(),
rate=f.getframerate(),
output=True)
# read data
data = f.readframes(CHUNK)
# play stream (3)
datas = []
while len(data) > 0:
data = f.readframes(CHUNK)
datas.append(data)
for d in tqdm(datas):
stream.write(d)
#stop stream (4)
stream.stop_stream()
stream.close()
# close PyAudio (5)
p.terminate()
record: