edge tts as a service
1.0.0
簡單的HTTP服務,使用Microsoft Edge的TTS引擎提供文本對語音功能,通過RESTFULE API支持多種語言和聲音。
英語| 中文
git clone https://github.com/doctoroyy/edge-tts-as-a-service
cd edge-tts-as-a-servicepip install -r requirements.txtpython main.py該服務將在http://localhost:5000可用
docker build -t edge-tts-as-a-service .docker run -d -p 5000:5000 edge-tts-as-a-service檢索所有支持的語音選項。
GET /voices
響應示例:
{
"code" : 200 ,
"message" : " OK " ,
"data" : [
{
"Name" : " en-US-GuyNeural " ,
"ShortName" : " en-US-GuyNeural " ,
"Gender" : " Male " ,
"Locale" : " en-US "
},
// ... more voices
]
}將文本轉換為語音並下載音頻文件。
POST /tts
請求主體:
{
"text" : " Hello, World! " ,
"voice" : " en-US-GuyNeural " , // Optional, defaults to "zh-CN-YunxiNeural"
"file_name" : " hello.mp3 " // Optional, defaults to "test.mp3"
}回覆:
使用流量輸出將文本轉換為語音,適用於實時播放。
POST /tts/stream
請求主體:
{
"text" : " Hello, World! " ,
"voice" : " en-US-GuyNeural " // Optional, defaults to "zh-CN-YunxiNeural"
}回覆:
import requests
# Get available voices
response = requests . get ( 'http://localhost:5000/voices' )
voices = response . json ()[ 'data' ]
# Text-to-Speech (Download)
data = {
"text" : "Hello, World!" ,
"voice" : "en-US-GuyNeural" ,
"file_name" : "output.mp3"
}
response = requests . post ( 'http://localhost:5000/tts' , json = data )
with open ( 'output.mp3' , 'wb' ) as f :
f . write ( response . content )
# Text-to-Speech (Streaming)
response = requests . post ( 'http://localhost:5000/tts/stream' , json = data , stream = True )
with open ( 'stream_output.mp3' , 'wb' ) as f :
for chunk in response . iter_content ( chunk_size = 8192 ):
f . write ( chunk ) # Get available voices
curl http://localhost:5000/voices
# Text-to-Speech (Download)
curl -X POST http://localhost:5000/tts
-H " Content-Type: application/json "
-d ' {"text":"Hello, World!", "voice":"en-US-GuyNeural"} '
--output output.mp3
# Text-to-Speech (Streaming)
curl -X POST http://localhost:5000/tts/stream
-H " Content-Type: application/json "
-d ' {"text":"Hello, World!", "voice":"en-US-GuyNeural"} '
--output stream_output.mp3尋找現成的前端界面?
?快速鏈接:React-audio-stream-demo
此React Demo為無縫TTS交互提供了功能齊全的前端,從而易於演示和集成Edge-TTS服務與用戶友好的接口。
問:如何選擇正確的聲音?
答:使用/voices端點獲取所有可用聲音的列表。根據位置和性別屬性選擇。
問:支持哪些語言?
答:多種語言,包括英語,中文,日語等。查看/voices端點以獲取完整列表。
問:什麼是音頻文件格式?
答:該服務生成MP3音頻文件。
歡迎問題和拉力請求。在提交公關之前,請:
麻省理工學院許可證