Update tts_stream.py

This commit is contained in:
GHUFRAN-HYDER 2024-03-14 23:18:14 +05:00 committed by GitHub
parent f8d8391c55
commit 5935062d5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,13 +11,19 @@ from utils.text import split_and_recombine_text
import sounddevice as sd
import queue
import threading
import pydub # Using pydub for audio playback
def play_audio(audio_queue):
while True:
chunk = audio_queue.get()
if chunk is None:
break
sd.play(chunk.cpu().numpy(), samplerate=24000)
sd.wait()
while True:
chunk = audio_queue.get()
if chunk is None:
break
# Convert PyTorch tensor to NumPy array and then to a WAV audio segment
audio_data = chunk.cpu().numpy().tobytes()
sound = pydub.AudioSegment(audio_data, frame_rate=24000, channels=1, sample_width=2)
# Play the audio segment
pydub.playback.play(sound)
if __name__ == '__main__':
parser = argparse.ArgumentParser()