Async release

This commit is contained in:
Carlos Mesquita
2024-07-23 08:40:35 +01:00
parent a4caecdb4f
commit 3cf9fa5cba
116 changed files with 5609 additions and 30630 deletions

View File

@@ -0,0 +1,22 @@
import os
from fastapi.concurrency import run_in_threadpool
from whisper import Whisper
from app.services.abc import ISpeechToTextService
class OpenAIWhisper(ISpeechToTextService):
def __init__(self, model: Whisper):
self._model = model
async def speech_to_text(self, file_path):
if os.path.exists(file_path):
result = await run_in_threadpool(
self._model.transcribe, file_path, fp16=False, language='English', verbose=False
)
return result["text"]
else:
print("File not found:", file_path)
raise Exception("File " + file_path + " not found.")