From 0aa18eaf548820e1b476658a5a6855882fb0a9ed Mon Sep 17 00:00:00 2001 From: bnfone <89687390+bnfone@users.noreply.github.com> Date: Mon, 24 Mar 2025 13:44:43 +0100 Subject: [PATCH] feature: OpenAI TTS API - requested changes feature: OpenAI TTS API - formatting & requested changes (see https://github.com/elebumm/RedditVideoMakerBot/pull/2268) --- TTS/openai_tts.py | 9 +++------ utils/.config.template.toml | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/TTS/openai_tts.py b/TTS/openai_tts.py index f439e2d..774a7a6 100644 --- a/TTS/openai_tts.py +++ b/TTS/openai_tts.py @@ -64,15 +64,12 @@ class OpenAITTS: # Select the model from configuration; default to 'tts-1' model = settings.config["settings"]["tts"].get("openai_model", "tts-1") - # Debug output: print which voice and model will be used - print(f"Using OpenAI TTS model: {model} with voice: {voice}") - - # Erstelle das Payload für den API-Request + # Create Payload for API-request payload = { "model": model, "voice": voice, "input": text, - "response_format": "mp3" # erlaubte Formate: "mp3", "aac", "opus", "flac", "pcm" oder "wav" + "response_format": "mp3" # allowed formats: "mp3", "aac", "opus", "flac", "pcm" or "wav" } headers = { "Authorization": f"Bearer {self.api_key}", @@ -82,7 +79,7 @@ class OpenAITTS: response = requests.post(self.api_url, headers=headers, json=payload) if response.status_code != 200: raise RuntimeError(f"Error from TTS API: {response.status_code} {response.text}") - # Schreibe die Binärdaten (mp3) direkt in die Datei. + # Write response as binary into file. with open(filepath, "wb") as f: f.write(response.content) except Exception as e: diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 3c98b15..4732782 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -57,5 +57,5 @@ silence_duration = { optional = true, example = "0.1", explanation = "Time in se no_emojis = { optional = false, type = "bool", default = false, example = false, options = [true, false,], explanation = "Whether to remove emojis from the comments" } openai_api_url = { optional = true, default = "https://api.openai.com/v1/", example = "https://api.openai.com/v1/", explanation = "The API endpoint URL for OpenAI TTS generation" } openai_api_key = { optional = true, example = "sk-abc123def456...", explanation = "Your OpenAI API key for TTS generation" } -openai_voice_name = { optional = false, default = "alloy", example = "alloy", explanation = "The voice used for OpenAI TTS generation", options = ["alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer"] } -openai_model = { optional = false, default = "tts-1", example = "tts-1", explanation = "The model variant used for OpenAI TTS generation", options = ["tts-1", "tts-1-hd"] } \ No newline at end of file +openai_voice_name = { optional = false, default = "alloy", example = "alloy", explanation = "The voice used for OpenAI TTS generation", options = ["alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer", "af_heart"] } +openai_model = { optional = false, default = "tts-1", example = "tts-1", explanation = "The model variant used for OpenAI TTS generation", options = ["tts-1", "tts-1-hd", "gpt-4o-mini-tts"] } \ No newline at end of file