mirror of
https://github.com/SillyTavern/SillyTavern-Extras.git
synced 2026-04-30 19:31:20 +00:00
Add rate to Edge TTS
This commit is contained in:
@@ -419,7 +419,7 @@ WAV audio file.
|
|||||||
`POST /api/edge-tts/generate`
|
`POST /api/edge-tts/generate`
|
||||||
#### **Input**
|
#### **Input**
|
||||||
```
|
```
|
||||||
{ "text": "Text to narrate", "voice": "af-ZA-AdriNeural" }
|
{ "text": "Text to narrate", "voice": "af-ZA-AdriNeural", "rate": 0 }
|
||||||
```
|
```
|
||||||
#### **Output**
|
#### **Output**
|
||||||
MP3 audio file.
|
MP3 audio file.
|
||||||
|
|||||||
@@ -676,10 +676,14 @@ def edge_tts_generate():
|
|||||||
abort(400, '"text" is required')
|
abort(400, '"text" is required')
|
||||||
if "voice" not in data or not isinstance(data["voice"], str):
|
if "voice" not in data or not isinstance(data["voice"], str):
|
||||||
abort(400, '"voice" is required')
|
abort(400, '"voice" is required')
|
||||||
|
if "rate" in data and isinstance(data['rate'], int):
|
||||||
|
rate = data['rate']
|
||||||
|
else:
|
||||||
|
rate = 0
|
||||||
# Remove asterisks
|
# Remove asterisks
|
||||||
data["text"] = data["text"].replace("*", "")
|
data["text"] = data["text"].replace("*", "")
|
||||||
try:
|
try:
|
||||||
audio = edge.generate_audio(text=data["text"], voice=data["voice"])
|
audio = edge.generate_audio(text=data["text"], voice=data["voice"], rate=rate)
|
||||||
return Response(audio, mimetype="audio/mpeg")
|
return Response(audio, mimetype="audio/mpeg")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ async def _async_generator_to_list(async_gen):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def generate_audio(text: str, voice: str) -> bytes:
|
def generate_audio(text: str, voice: str, rate: int) -> bytes:
|
||||||
audio = edge_tts.Communicate(text, voice)
|
sign = '+' if rate > 0 else '-'
|
||||||
|
rate = f'{sign}{abs(rate)}%'
|
||||||
|
audio = edge_tts.Communicate(text=text, voice=voice, rate=rate)
|
||||||
chunks = asyncio.run(_async_generator_to_list(_iterate_chunks(audio)))
|
chunks = asyncio.run(_async_generator_to_list(_iterate_chunks(audio)))
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user