diff --git a/lollms/services/open_ai_tts/lollms_openai_tts.py b/lollms/services/open_ai_tts/lollms_openai_tts.py index bfbeb67..ddaba40 100644 --- a/lollms/services/open_ai_tts/lollms_openai_tts.py +++ b/lollms/services/open_ai_tts/lollms_openai_tts.py @@ -105,4 +105,17 @@ class LollmsOpenAITTS(LollmsTTS): sd.wait() # Example usage - play_audio(speech_file_path) \ No newline at end of file + play_audio(speech_file_path) + + def tts_file(self, text, speaker=None, file_name_or_path:Path|str=None, language="en", use_threading=False): + speech_file_path = file_name_or_path + response = self.client.audio.speech.create( + model=self.model, + voice=self.voice, + input=text, + response_format="wav" + + ) + + response.write_to_file(speech_file_path) + return file_name_or_path \ No newline at end of file diff --git a/lollms/services/xtts/lollms_xtts.py b/lollms/services/xtts/lollms_xtts.py index d27da21..fc5362b 100644 --- a/lollms/services/xtts/lollms_xtts.py +++ b/lollms/services/xtts/lollms_xtts.py @@ -259,7 +259,7 @@ class LollmsXTTS(LollmsTTS): print("Request failed with status code:", response.status_code) return False - def tts_file(self, text, speaker, file_name_or_path, language="en"): + def tts_file(self, text, file_name_or_path, speaker=None, language="en")->str: url = f"{self.xtts_base_url}/tts_file" # Define the request body @@ -284,6 +284,8 @@ class LollmsXTTS(LollmsTTS): else: print("Request failed with status code:", response.status_code) + return file_name_or_path + def tts_audio(self, text, speaker, file_name_or_path:Path|str=None, language="en", use_threading=False): voice=self.app.config.xtts_current_voice if speaker is None else speaker index = find_first_available_file_index(self.output_folder, "voice_sample_",".wav") diff --git a/lollms/tts.py b/lollms/tts.py index 4d9285f..4a95f91 100644 --- a/lollms/tts.py +++ b/lollms/tts.py @@ -62,7 +62,7 @@ class LollmsTTS: self.voices = [] # To be filled by the child class self.models = [] # To be filled by the child class - def tts_file(self, text, speaker, file_name_or_path, language="en"): + def tts_file(self, text, file_name_or_path, speaker=None, language="en")->str: """ Converts the given text to speech and saves it to a file.