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音频文件。
欢迎问题和拉力请求。在提交公关之前,请:
麻省理工学院许可证