From 5df64847eae4466e94ccc0fc5fd53dff23f8e051 Mon Sep 17 00:00:00 2001 From: fred Date: Thu, 22 Feb 2024 12:48:26 +0100 Subject: [PATCH] transformer.js / api.py --- .../api.py | 30 +++++++++++++++++++ .../readme | 1 + 2 files changed, 31 insertions(+) create mode 100644 adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/api.py diff --git a/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/api.py b/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/api.py new file mode 100644 index 000000000..ddaf95c5d --- /dev/null +++ b/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/api.py @@ -0,0 +1,30 @@ +#!/bin/python3 +from fastapi import FastAPI, File, UploadFile +from fastapi.responses import JSONResponse +import whisper + +app = FastAPI() + +whisper = whisper.load_model("medium.en") + +@app.post("/speechToText") +async def speech_to_text(file: UploadFile = File(...)): + try: + # Save the uploaded audio file locally + audio_path = "temp_audio.wav" + with open(audio_path, "wb") as audio_file: + audio_file.write(file.file.read()) + + # Use whisper to convert speech to text + text = whisper.transcribe(audio_path,language="en")['text'] + + # Return the transcribed text + return text + + except Exception as e: + return JSONResponse(content={"error": str(e)}, status_code=500) + +if __name__ == "__main__": + import uvicorn + + uvicorn.run(app, host="0.0.0.0", port=9000) diff --git a/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/readme b/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/readme index 2f8373e61..52f338969 100644 --- a/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/readme +++ b/adventure/games/nathan.fleury@ynov.com_benjamin.bouteille@ynov.com/readme @@ -28,4 +28,5 @@ mv ./rooms/young_hacker.sh ./rooms/start.sh <3<3<3 +https://github.com/xenova/whisper-web