Skip to content

Commit

Permalink
Merge pull request #24 from ultrasev/concurrent-recording
Browse files Browse the repository at this point in the history
style(src.deploy.whisper): accept prompt from the docker environment …
  • Loading branch information
ultrasev authored Apr 18, 2024
2 parents e8bf539 + c252e5f commit a711fdd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/docker/whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
from starlette.requests import Request
from starlette.responses import JSONResponse

model_size = os.getenv('MODEL', 'base')
# Accept the following environment variables from Docker
MODEL_SIZE = os.getenv('MODEL', 'base')
PROMPT = os.getenv('PROMPT', '基于FastWhisper的低延迟语音转写服务')


class ValidateFileTypeMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
if request.method.lower() == "post":
try:
logger.info(f"Request: {request.url}")
response = await call_next(request)
return response
except av.error.InvalidDataError:
Expand Down Expand Up @@ -54,7 +57,7 @@ def __init__(
model_size: str,
device: str = "auto",
compute_type: str = "default",
prompt: str = '实时/低延迟语音转写服务,林黛玉、倒拔、杨柳树、鲁迅、周树人、关键词、转写正确') -> None:
prompt: str = PROMPT) -> None:
""" FasterWhisper 语音转写
Args:
Expand Down Expand Up @@ -97,7 +100,7 @@ def _process():

@app.post("/v1/audio/transcriptions")
async def _transcribe(file: UploadFile = File(...)):
with Transcriber(model_size) as stt:
with Transcriber(MODEL_SIZE) as stt:
audio = await file.read()
text = ','.join([seg async for seg in stt(audio)])
return {"text": text}

0 comments on commit a711fdd

Please sign in to comment.