Skip to content

Commit

Permalink
lang param.
Browse files Browse the repository at this point in the history
  • Loading branch information
boocmp committed Aug 12, 2024
1 parent 6bb4cd8 commit 355d24e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/runners/audio_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def __init__(self):
self.model = WhisperModel(model, device=device, compute_type=compute_type)

@bentoml.Runnable.method(batchable=False)
def transcribe_audio(self, audio):
def transcribe_audio(self, audio, lang):
if len(lang) < 2:
lang = "en"
else:
lang = lang[0:2]

segments, info = self.model.transcribe(
audio,
vad_filter=True,
vad_parameters=dict(min_silence_duration_ms=500),
language="en",
language=lang,
)

text = ""
Expand Down
9 changes: 7 additions & 2 deletions src/stt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async def handleSticky():

@app.post("/up")
async def handleUpstream(
pair: str, request: Request, is_valid_brave_key=Depends(check_stt_request)
pair: str,
request: Request,
lang: str = "en",
is_valid_brave_key=Depends(check_stt_request),
):
if not is_valid_brave_key:
return JSONResponse(
Expand All @@ -57,7 +60,9 @@ async def handleUpstream(
if len(chunk) == 0:
break
mic_data += chunk
transciption = await runner_audio_transcriber.async_run(io.BytesIO(mic_data))
transciption = await runner_audio_transcriber.async_run(
io.BytesIO(mic_data), lang
)
text = transciption["text"]
if text:
await pipe.push(ipc.messages.Text(text, False))
Expand Down

0 comments on commit 355d24e

Please sign in to comment.