adding in tts logic with gcp

This commit is contained in:
talksik
2023-04-29 08:44:21 -07:00
parent cd4c26966a
commit 6820b49f0e
2 changed files with 44 additions and 1 deletions
+20 -1
View File
@@ -1,5 +1,6 @@
from flask import Flask, request, abort
from flask import Flask, request, abort, send_file
from tempfile import NamedTemporaryFile
import tts
import whisper
# Load the Whisper model:
@@ -44,6 +45,24 @@ def transcribe():
return {"results": results}
# endpoint to convert text to speech and return the file
@app.route("/tts", methods=["GET"])
def text_to_speech():
# get the text from the request
text = request.form.get("text")
if not text:
abort(400, "Please provide text to convert to speech!")
# call the text_to_wav function from tts.py
fileName = tts.text_to_wav(
voice_name="en-GB-Neural2-B",
text=text,
)
# return the file
return send_file(f"{fileName}.wav", mimetype="audio/wav")
if __name__ == "__main__":
# 0.0.0.0 opens up to all ipv4 addresses
app.run(host="0.0.0.0", port=5001, debug=True)