From 5935062d5af2d8b00a38149d009d1b57dc68aa95 Mon Sep 17 00:00:00 2001 From: GHUFRAN-HYDER <65118907+GHUFRAN-HYDER@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:18:14 +0500 Subject: [PATCH] Update tts_stream.py --- tortoise/tts_stream.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tortoise/tts_stream.py b/tortoise/tts_stream.py index 32a129d..9b8df6a 100644 --- a/tortoise/tts_stream.py +++ b/tortoise/tts_stream.py @@ -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()