Spaces:
Running
Running
add docstring
Browse files
app.py
CHANGED
|
@@ -3,9 +3,31 @@ from elevenlabs.client import ElevenLabs
|
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def generate_speech(text, api_key, voice_id, model_id, language_code, output_format):
|
| 7 |
"""
|
| 8 |
Convert input text to speech using ElevenLabs API and return the audio file path.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
if not text.strip():
|
| 11 |
return None, "❌ Text is empty."
|
|
|
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
def generate_speech(text = "", api_key = "", voice_id = "JBFqnCBsd6RMkjVDRZzb", model_id = "eleven_v3", language_code = "en", output_format = "mp3_22050_32"):
|
| 7 |
"""
|
| 8 |
Convert input text to speech using ElevenLabs API and return the audio file path.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
text (str): Required. The input text to be converted into speech.
|
| 12 |
+
api_key (str): Required. The ElevenLabs API key used to authenticate the request. This should be kept secret and treated like a password.
|
| 13 |
+
|
| 14 |
+
voice_id (str): The ID of the voice to use for speech generation. Default: "JBFqnCBsd6RMkjVDRZzb". Other available voices can be found at: https://elevenlabs.io/app/default-voices
|
| 15 |
+
|
| 16 |
+
model_id (str): The ID of the ElevenLabs model to use. Typically one of: "eleven_v3" (default) or "eleven_multilingual_v2"
|
| 17 |
+
|
| 18 |
+
language_code (str): The two-letter ISO 639-1 language code specifying the language of the input text. Example: "en" for English, "lv" for Latvian. Full list: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
| 19 |
+
|
| 20 |
+
output_format (str): The desired output audio format. Default: "mp3_22050_32". Other formats are listed here: https://elevenlabs.io/docs/api-reference/text-to-speech/convert#request.query.output_format.output_format
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
tuple
|
| 24 |
+
A tuple containing:
|
| 25 |
+
|
| 26 |
+
audio_file_path : str or None
|
| 27 |
+
The file path to the generated audio file if the speech synthesis was successful, or None if an error occurred.
|
| 28 |
+
|
| 29 |
+
status_message : str
|
| 30 |
+
A human-readable message indicating the result of the operation, such as a success confirmation or an error description.
|
| 31 |
"""
|
| 32 |
if not text.strip():
|
| 33 |
return None, "❌ Text is empty."
|