AI TTS
1.0.0
AI TTS使用Elevenlabs API
您将首先需要安装所需的库。您可以使用PIP和以下命令安装它们: pip3 install -r requirements.txt
对于孤立的环境(推荐),使用以下方式创建和激活虚拟环境:
python3 -m venv venv
source venv/bin/activate # On Linux/macOS
venvScriptsactivate # On Windows
pip3 install -r requirements.txt
要使用该程序,您需要提供ElevenLabs API密钥。您可以通过在此处注册获得API密钥。获得API密钥后,您应该将其设置为名为Elevenlabs_api_key的环境变量。
请按照以下步骤持续设置Elevenlabs_api_key环境变量(建议):
在Linux或MacOS上:
.zshrc文件。例如: nano ~/.zshrcexport ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here 。source ~/.zshrc以加载更改。在Windows上:
ELEVENLABS_API_KEY的变量名称和您的实际API键,以获取变量值。另外,您只能在当前会话中临时设置Elevenlabs_api_key环境变量,如下所示:
在Linux或MacOS上:
export ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here 。在Windows上:
setx ELEVENLABS_API_KEY "your_api_key_here"your_api_key_here 。设置了Elevenlabs_api_key环境变量后,您可以按照以下“使用”部分中的描述运行程序。
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
要使用pninz6obpgdqgcfmajgb语音ID转换为input.txt中的文本,请运行以下命令:
python3 TTS.py -a -f input.txt --voice-id pNInz6obpgDQGcFmaJgB
直接输入字符串转换为语音:
python3 TTS.py -a --text "This is an example block of text"
要获取最新的AI新闻并使用文本进行语音阅读,请运行以下命令之一。
要使用默认名称AUDIO.WAV生成音频文件:
python3 TTS.py -a --AI
要生成带有自定义名称的音频文件:
python3 TTS.py -a --AI -o AI_news.wav
仅播放音频:
python3 TTS.py -s --AI