AI TTS usando ElevenLabs API
Primero deberá instalar las bibliotecas requeridas. Puede instalarlos utilizando PIP con el siguiente comando: pip3 install -r requirements.txt
Para un entorno aislado (recomendado), cree y active un entorno virtual usando:
python3 -m venv venv
source venv/bin/activate # On Linux/macOS
venvScriptsactivate # On Windows
pip3 install -r requirements.txt
Para usar el programa, debe suministrar su tecla API de ElevenLabs. Puede obtener una clave API registrándose aquí. Después de obtener su clave API, debe configurarla como una variable de entorno llamada ElevenLabs_api_Key.
Siga estos pasos para establecer la variable de entorno ElevenLabs_api_Key de manera persistente (recomendado):
En Linux o macOS:
.zshrc con su editor de texto favorito. Por ejemplo: nano ~/.zshrcexport ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here con su clave API real.source ~/.zshrc en el terminal para cargar los cambios.En Windows:
ELEVENLABS_API_KEY para el nombre de la variable y su clave API real para el valor variable.Alternativamente, puede establecer la variable de entorno ElevenLabs_API_Key temporalmente, solo para la sesión actual, como sigue:
En Linux o macOS:
export ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here con su clave API real.En Windows:
setx ELEVENLABS_API_KEY "your_api_key_here"your_api_key_here con su clave API real.Una vez que se establece la variable de entorno ElevenLabs_api_Key, puede ejecutar el programa como se describe en la sección de uso a continuación.
TTS.py [-h] (-a | -s | --get-voices) [-v VOICE_ID]
[-t TEXT | -f FILE | -u URL | --ai | --gear | --business | --culture | --science | --security]
[-m MODEL] [-o OUTPUT]
-h, --help show this help message and exit
-a, --audio Use /v1/text-to-speech API endpoint
-s, --stream Use /v1/text-to-speech/{voice_id}/stream API endpoint
--get-voices Retrieve the available voices
-v VOICE_ID, --voice-id VOICE_ID Voice ID to use for the conversion
-t TEXT, --text TEXT Text to convert to speech
-f FILE, --file FILE Text file to convert to speech
-u URL, --url URL BETA: URL of article to convert to speech
--ai Read the latest AI news
--gear Read the latest gear news
--business Read the latest business news
--culture Read the latest culture news
--science Read the latest science news
--security Read the latest security news
-m MODEL, --model MODEL ElevenLabs model to use
-o OUTPUT, --output OUTPUT Output to a .wav file
Para convertir el texto en input.txt a discurso utilizando el ID de voz pninz6obpgdqgcfmajgb, ejecute el siguiente comando:
python3 TTS.py -a -f input.txt --voice-id pNInz6obpgDQGcFmaJgB
Para ingresar directamente una cadena para convertir a discurso:
python3 TTS.py -a --text "This is an example block of text"
Para obtener las últimas noticias de la IA y leerlo usando texto a discurso, ejecute uno de los siguientes comandos.
Para generar un archivo de audio con el nombre predeterminado Audio.wav:
python3 TTS.py -a --AI
Para generar un archivo de audio con un nombre personalizado:
python3 TTS.py -a --AI -o AI_news.wav
Para transmitir solo el audio:
python3 TTS.py -s --AI