adding in serverside app for stt

This commit is contained in:
talksik
2023-04-28 15:00:09 -07:00
parent 49191b2eed
commit f2c8a482cd
4 changed files with 54 additions and 0 deletions
Vendored
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
+48
View File
@@ -0,0 +1,48 @@
from flask import Flask, request, abort
from tempfile import NamedTemporaryFile
import whisper
# Load the Whisper model:
model = whisper.load_model("base")
app = Flask(__name__)
@app.route("/")
def helloWorld():
return "Hello, World!"
@app.route("/transcribe", methods=["POST"])
def transcribe():
if not request.files:
# If the user didn't submit any files, return a 400 (Bad Request) error.
abort(400, "No files submitted!")
# For each file, let's store the results in a list of dictionaries.
results = []
# Loop over every file that the user submitted.
for filename, handle in request.files.items():
# Create a temporary file.
# The location of the temporary file is available in `temp.name`.
temp = NamedTemporaryFile()
# Write the user's uploaded file to the temporary file.
# The file will get deleted when it drops out of scope.
handle.save(temp)
# Let's get the transcript of the temporary file.
result = model.transcribe(temp.name)
# Now we can store the result object for this file.
results.append(
{
"filename": filename,
"transcript": result["text"],
}
)
# This will be automatically converted to JSON.
return {"results": results}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
View File