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