บริการ HTTP อย่างง่ายที่ให้ฟังก์ชั่นการพูดแบบข้อความโดยใช้เอ็นจิ้น TTS ของ Microsoft Edge รองรับหลายภาษาและเสียงผ่าน APIs
ภาษาอังกฤษ | 中文
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
การสาธิตปฏิกิริยานี้ให้ส่วนหน้าอย่างสมบูรณ์สำหรับการโต้ตอบ TTS ที่ไร้รอยต่อทำให้ง่ายต่อการสาธิตและรวมบริการ Edge-TTS เข้ากับอินเทอร์เฟซที่ใช้งานง่าย
ถาม: ฉันจะเลือกเสียงที่ถูกต้องได้อย่างไร?
ตอบ: ใช้จุดสิ้นสุด /voices เพื่อรับรายการเสียงที่มีอยู่ทั้งหมด เลือกตามคุณสมบัติของสถานที่และเพศ
ถาม: สนับสนุนภาษาอะไร?
ตอบ: หลายภาษารวมถึงภาษาอังกฤษจีนญี่ปุ่น ฯลฯ ตรวจสอบจุดสิ้นสุด /voices สำหรับรายการที่สมบูรณ์
ถาม: รูปแบบไฟล์เสียงคืออะไร?
ตอบ: บริการสร้างไฟล์เสียง MP3
ยินดีต้อนรับปัญหาและคำขอดึง ก่อนส่ง PR กรุณา:
ใบอนุญาต MIT