Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ import asyncio
|
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
| 12 |
|
| 13 |
-
async def TextToAudioFile(text) -> str:
|
| 14 |
|
| 15 |
|
| 16 |
file_path = r"main.mp3"
|
|
@@ -18,7 +18,7 @@ async def TextToAudioFile(text) -> str:
|
|
| 18 |
if os.path.exists(file_path):
|
| 19 |
os.remove(file_path)
|
| 20 |
|
| 21 |
-
communicate = edge_tts.Communicate(text, voice=
|
| 22 |
await communicate.save(file_path)
|
| 23 |
|
| 24 |
with open(file_path, 'rb') as audio_file:
|
|
@@ -35,7 +35,8 @@ async def TextToAudioFile(text) -> str:
|
|
| 35 |
def tts():
|
| 36 |
data = request.get_json()
|
| 37 |
text = data.get('text')
|
| 38 |
-
|
|
|
|
| 39 |
return jsonify({'audio': audio_base64}), 200
|
| 40 |
|
| 41 |
if __name__ == '__main__':
|
|
|
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
| 12 |
|
| 13 |
+
async def TextToAudioFile(text:str,model:str) -> str:
|
| 14 |
|
| 15 |
|
| 16 |
file_path = r"main.mp3"
|
|
|
|
| 18 |
if os.path.exists(file_path):
|
| 19 |
os.remove(file_path)
|
| 20 |
|
| 21 |
+
communicate = edge_tts.Communicate(text, voice=model, pitch='+5Hz', rate='+10%')
|
| 22 |
await communicate.save(file_path)
|
| 23 |
|
| 24 |
with open(file_path, 'rb') as audio_file:
|
|
|
|
| 35 |
def tts():
|
| 36 |
data = request.get_json()
|
| 37 |
text = data.get('text')
|
| 38 |
+
model = data.get('model',"en-GB-SoniaNeural")
|
| 39 |
+
audio_base64 = asyncio.run(TextToAudioFile(text,model))
|
| 40 |
return jsonify({'audio': audio_base64}), 200
|
| 41 |
|
| 42 |
if __name__ == '__main__':
|