diff --git a/.DS_Store b/.DS_Store index 3d23a4b..9959549 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/stt/.vscode/settings.json b/stt/.vscode/settings.json new file mode 100644 index 0000000..3445835 --- /dev/null +++ b/stt/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} diff --git a/stt/app.py b/stt/app.py new file mode 100644 index 0000000..c5d60d5 --- /dev/null +++ b/stt/app.py @@ -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) diff --git a/stt/requirements.txt b/stt/requirements.txt new file mode 100644 index 0000000..e69de29