當前位置: 妍妍網 > 碼農

Edge-TTS:微軟最新開源的支持多種中文音色的文本轉語音工具,平替付費軟體降低開發成本

2024-03-08碼農

計畫簡介

Edge-TTS是由微軟推出的文本轉語音Python庫,透過微軟Azure Cognitive Services轉化文本為自然語音。適合需要語音功能的開發者,GitHub上超3000星。作為國內付費TTS服務的替代品,Edge-TTS支持40多種語言和300種聲音,提供優質的語音輸出,滿足不同開發需求。

掃碼加入交流群

獲得更多技術支持和交流

(請註明自己的職業)

安裝

要安裝它,執行以下命令:

$ pip install edge-tts

如果只想使用edge-tts和edge-playback命令,最好使用 pipx:

$ pipx install edge-tts

用法

基本用法

如果你想使用edge-tts命令,只需使用以下命令執行即可:

$ edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt

如果你想立即播放帶有字幕的內容,可以使用以下edge-playback命令:

$ edge-playback --text "Hello, world!"

註意以上需要安裝mpv命令列播放器。

所有命令也都edge-tts可以工作。edge-playback

改變聲音

如果你想改變語音的語言或者更一般地,改變語音本身。

你首先需要使用 --list-voices 選項檢查可用的語音。

$ edge-tts --list-voicesName: Microsoft Server Speech Text to Speech Voice(af-ZA, AdriNeural)ShortName: af-ZA-AdriNeuralGender: FemaleLocale: af-ZAName: Microsoft Server Speech Text to Speech Voice(am-ET, MekdesNeural)ShortName: am-ET-MekdesNeuralGender: FemaleLocale: am-ETName: Microsoft Server Speech Text to Speech Voice(ar-EG, SalmaNeural)ShortName: ar-EG-SalmaNeuralGender: FemaleLocale: ar-EGName: Microsoft Server Speech Text to Speech Voice(ar-SA, ZariyahNeural)ShortName: ar-SA-ZariyahNeuralGender: FemaleLocale: ar-SA...$ edge-tts --voice ar-EG-SalmaNeural --text "مرحبا كيف حالك؟" --write-media hello_in_arabic.mp3 --write-subtitles hello_in_arabic.vtt

調整語速、音量和音調

可以對生成的語音進行細微修改。

$ edge-tts --rate=-50% --text "Hello, world!" --write-media hello_with_rate_halved.mp3 --write-subtitles hello_with_rate_halved.vtt$ edge-tts --volume=-50% --text "Hello, world!" --write-media hello_with_volume_halved.mp3 --write-subtitles hello_with_volume_halved.vtt$ edge-tts --pitch=-50Hz --text "Hello, world!" --write-media hello_with_pitch_halved.mp3 --write-subtitles hello_with_pitch_halved.vtt

此外,必須使用 --rate=-50% 而不是 --rate -50%(註意等號的缺失),否則 -50% 將被解釋為另一個參數。

關於 edge-playback 命令的說明

edge-playback 實際上是 edge-tts 的一個封裝,用於播放生成的語音。它接受與 edge-tts 選項相同的參數。

計畫連結

https://github.com/rany2/edge-tts

關註「 AGI光年 」公眾號