mirror of
https://github.com/neonbjb/tortoise-tts.git
synced 2026-01-20 15:40:37 +01:00
Update tts_stream.py
This commit is contained in:
parent
f8d8391c55
commit
5935062d5a
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue