From a094d4f9dac7f57ad1eb54190a562fd2972ad96d Mon Sep 17 00:00:00 2001 From: erew123 <35898566+erew123@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:25:08 +0000 Subject: [PATCH] Completed autoplay at command line Added additional requirement. Lowered the repetition on the start-up warning when its taking a while for the model to load. --- requirements_nvidia.txt | 1 + requirements_other.txt | 1 + script.py | 4 ++-- tts_server.py | 18 +++++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/requirements_nvidia.txt b/requirements_nvidia.txt index ef574c4..b8d22e9 100644 --- a/requirements_nvidia.txt +++ b/requirements_nvidia.txt @@ -12,3 +12,4 @@ importlib-metadata>=4.8.1 packaging>=23.2 pydantic>=1.10.13 sounddevice>=0.4.6 +python-multipart>=0.0.6 diff --git a/requirements_other.txt b/requirements_other.txt index 8bc9597..6566ced 100644 --- a/requirements_other.txt +++ b/requirements_other.txt @@ -12,3 +12,4 @@ importlib-metadata>=4.8.1 packaging>=23.2 pydantic>=1.10.13 sounddevice>=0.4.6 +python-multipart>=0.0.6 diff --git a/script.py b/script.py index 30eb714..38bac24 100644 --- a/script.py +++ b/script.py @@ -252,7 +252,7 @@ else: timeout = 120 # Adjust the timeout as needed # Introduce a delay before starting the check loop -time.sleep(25) # Wait 25 secs before checking if the tts_server.py has started up. +time.sleep(26) # Wait 26 secs before checking if the tts_server.py has started up. start_time = time.time() while time.time() - start_time < timeout: try: @@ -264,7 +264,7 @@ while time.time() - start_time < timeout: print( f"[{params['branding']}Startup] \033[91mWarning\033[0m TTS Subprocess has NOT started up yet, Will keep trying for 120 seconds maximum. Please wait." ) - time.sleep(1) + time.sleep(4) else: print( f"[{params['branding']}Startup] Startup timed out. Check the server logs for more information." diff --git a/tts_server.py b/tts_server.py index 95cd725..57ac453 100644 --- a/tts_server.py +++ b/tts_server.py @@ -674,7 +674,21 @@ import re import uuid import numpy as np import soundfile as sf -import sounddevice as sd +import sys + +# Check for PortAudio library on Linux +try: + import sounddevice as sd + sounddevice_installed=True +except OSError: + print(f"[{params['branding']}Startup] \033[91mInfo\033[0m PortAudio library not found. If you wish to play TTS in standalone mode through the API suite") + print(f"[{params['branding']}Startup] \033[91mInfo\033[0m please install PortAudio. This will not affect any other features or use of Alltalk.") + print(f"[{params['branding']}Startup] \033[91mInfo\033[0m If you don't know what the API suite is, then this message is nothing to worry about.") + sounddevice_installed=False + if sys.platform.startswith('linux'): + print(f"[{params['branding']}Startup] \033[91mInfo\033[0m On Linux, you can use the following command to install PortAudio:") + print(f"[{params['branding']}Startup] \033[91mInfo\033[0m sudo apt-get install portaudio19-dev") + from typing import Union, Dict from pydantic import BaseModel, ValidationError, Field @@ -880,6 +894,8 @@ async def tts_generate( else: cleaned_string = text_input await generate_audio(cleaned_string, character_voice_gen, language, output_file_path) + if sounddevice_installed == False: + autoplay = False if autoplay: play_audio(output_file_path, autoplay_volume) return JSONResponse(content={"status": "generate-success", "output_file_path": str(output_file_path), "output_file_url": str(output_file_url)}, status_code=200)