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