feature: OpenAI TTS API - requested changes

feature: OpenAI TTS API - formatting & requested changes (see https://github.com/elebumm/RedditVideoMakerBot/pull/2268)
pull/2268/head
bnfone 6 months ago
parent e137dbb40d
commit 0aa18eaf54

@ -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:

@ -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"] }
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"] }
Loading…
Cancel
Save