Python SDK: allow language selection for local Whisper transcription
Hi @josancamon19 — following the contribution guide’s invitation to propose paid work, would you sponsor a US$50 Python SDK enhancement for local Whisper language selection, payable through the documented PayPal process after acceptance and merge?
At main cb23ae331fe143d13cd1c4c0facee466c52a94d3, sdks/python/omi/stt/whisper.py accepts multilingual model names but calls Whisper with language="en"; callers cannot select German or automatic detection. I have prepared a small implementation adding keyword-only language: Optional[str] = "en", forwarding it to model.transcribe, preserving defaults and the injected runner’s bytes-only contract, and documenting multilingual model selection. The new regression tests failed for the new options before the change; all 11 Python SDK tests pass after it through the real audio queue, PCM conversion, transcription wrapper and callback, with only the Whisper model stubbed. This verifies configuration and audio plumbing, not real speech recognition accuracy; repository-wide local preflight now passes all 18 selected checks, the CI manifest passes with the five changed paths, and the workflow passes actionlint v1.7.12. This is an AI-assisted contribution prepared with @TheoFrk’s authorization, and no bounty, reservation or payment is assumed unless you confirm the scope.
Proposed usage:
await transcribe(
audio_queue, "", on_transcript=print,
engine="whisper", model_name="tiny", language="de",
)
# language=None requests Whisper's automatic detection with a multilingual model.
Proposed verification:
PYTHONPATH=sdks/python python -m pytest sdks/python/tests -q
The prepared patch covers the implementation, default/German/automatic language forwarding tests, custom-runner compatibility, SDK documentation and execution of SDK tests in the existing Python workflow.
Prepared patch for review (not yet a PR; no payment agreement)
Base: cb23ae331fe143d13cd1c4c0facee466c52a94d3. My connected GitHub tooling does not provide fork creation, so the patch is included here for inspection while that submission prerequisite is unresolved.
diff --git a/.github/workflows/python-cli-ci.yml b/.github/workflows/python-cli-ci.yml
index 638a9c1..0e42cfb 100644
--- a/.github/workflows/python-cli-ci.yml
+++ b/.github/workflows/python-cli-ci.yml
@@ -5,11 +5,13 @@ on:
branches: [main]
paths:
- 'sdks/python-cli/**'
+ - 'sdks/python/**'
- '.github/workflows/python-cli-ci.yml'
pull_request:
branches: [main]
paths:
- 'sdks/python-cli/**'
+ - 'sdks/python/**'
- '.github/workflows/python-cli-ci.yml'
permissions:
@@ -20,6 +22,24 @@ defaults:
working-directory: sdks/python-cli
jobs:
+ sdk-tests:
+ name: Python SDK / Whisper language
+ runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: sdks/python
+ steps:
+ - uses: actions/checkout@v7
+ - uses: actions/setup-python@v6
+ with:
+ python-version: '3.10'
+ - name: Install hermetic SDK test dependencies
+ run: python -m pip install pytest numpy
+ - name: Run SDK tests without devices or model downloads
+ run: python -m pytest -q
+ env:
+ PYTHONPATH: .
+
tests:
name: ${{ matrix.label }}
strategy:
diff --git a/docs/doc/developer/sdk/python.mdx b/docs/doc/developer/sdk/python.mdx
index 46d5a37..604213b 100644
--- a/docs/doc/developer/sdk/python.mdx
+++ b/docs/doc/developer/sdk/python.mdx
@@ -141,6 +141,31 @@ The SDK requires the Opus audio codec library:
</Step>
</Steps>
+### Local Whisper language selection
+
+Install the optional local engine with `pip install 'omi-sdk[whisper]'`.
+Whisper defaults to the English-only `tiny.en` model and `language="en"`.
+For another language, select a multilingual model (without the `.en` suffix)
+and pass its language code through the transcription wrapper:
+
+```python
+from omi.transcribe import transcribe
+
+await transcribe(
+ audio_queue,
+ "", # The shared wrapper requires this argument; Whisper does not use it.
+ on_transcript=print,
+ engine="whisper",
+ model_name="tiny",
+ language="de",
+)
+```
+
+Pass `language=None` with a multilingual model to let Whisper detect the language
+for each audio batch. The local engine batches approximately five seconds of
+16 kHz mono PCM before transcription. When supplying a custom `runner=`, the
+runner still receives only PCM bytes and controls its own language selection.
+
---
## API Reference
diff --git a/sdks/python/README.md b/sdks/python/README.md
index f219b14..cbfaede 100644
--- a/sdks/python/README.md
+++ b/sdks/python/README.md
@@ -87,6 +87,31 @@ A pip-installable Python SDK for connecting to Omi wearable devices over Bluetoo
</Step>
</Steps>
+### Local Whisper language selection
+
+Install the optional local engine with `pip install 'omi-sdk[whisper]'`.
+Whisper defaults to the English-only `tiny.en` model and `language="en"`.
+For another language, select a multilingual model (without the `.en` suffix)
+and pass its language code through the transcription wrapper:
+
+```python
+from omi.transcribe import transcribe
+
+await transcribe(
+ audio_queue,
+ "", # The shared wrapper requires this argument; Whisper does not use it.
+ on_transcript=print,
+ engine="whisper",
+ model_name="tiny",
+ language="de",
+)
+```
+
+Pass `language=None` with a multilingual model to let Whisper detect the language
+for each audio batch. The local engine batches approximately five seconds of
+16 kHz mono PCM before transcription. When supplying a custom `runner=`, the
+runner still receives only PCM bytes and controls its own language selection.
+
## Development
diff --git a/sdks/python/omi/stt/whisper.py b/sdks/python/omi/stt/whisper.py
index deceb9e..cdd1593 100644
--- a/sdks/python/omi/stt/whisper.py
+++ b/sdks/python/omi/stt/whisper.py
@@ -11,9 +11,22 @@ class WhisperTranscriber:
Feature gate: only importable/usable when a runner is provided or whisper is installed.
"""
- def __init__(self, *, model_name: str = "tiny.en", runner: Optional[Callable[[bytes], str]] = None) -> None:
+ def __init__(
+ self,
+ *,
+ model_name: str = "tiny.en",
+ runner: Optional[Callable[[bytes], str]] = None,
+ language: Optional[str] = "en",
+ ) -> None:
+ """Use a language code or None for Whisper's language detection.
+
+ Non-English audio requires a multilingual model (for example, "tiny").
+ An injected runner continues to receive only PCM bytes and owns its
+ own language configuration.
+ """
self.model_name = model_name
self.runner = runner
+ self.language = language
self._model = None
if runner is None:
try:
@@ -53,5 +66,5 @@ class WhisperTranscriber:
import numpy as np # type: ignore
audio = np.frombuffer(pcm, dtype=np.int16).astype(np.float32) / 32768.0
- result = self._model.transcribe(audio, fp16=False, language="en")
+ result = self._model.transcribe(audio, fp16=False, language=self.language)
return (result.get("text") or "").strip()
diff --git a/sdks/python/tests/test_whisper_language.py b/sdks/python/tests/test_whisper_language.py
new file mode 100644
index 0000000..3693c66
--- /dev/null
+++ b/sdks/python/tests/test_whisper_language.py
@@ -0,0 +1,84 @@
+import asyncio
+import contextlib
+import sys
+from types import SimpleNamespace
+
+import numpy as np
+import pytest
+
+from omi.transcribe import transcribe
+
+
[email protected](
+ "options, expected_model, expected_language",
+ [
+ ({}, "tiny.en", "en"),
+ ({"model_name": "tiny", "language": "de"}, "tiny", "de"),
+ ({"model_name": "tiny", "language": None}, "tiny", None),
+ ],
+)
+def test_whisper_language_through_audio_queue(
+ monkeypatch, options, expected_model, expected_language
+):
+ calls = []
+ loaded_models = []
+
+ def model_transcribe(audio, **kwargs):
+ calls.append((audio, kwargs))
+ return {"text": " Guten Tag "}
+
+ def load_model(name):
+ loaded_models.append(name)
+ return SimpleNamespace(transcribe=model_transcribe)
+
+ monkeypatch.setitem(sys.modules, "whisper", SimpleNamespace(load_model=load_model))
+
+ async def exercise():
+ queue = asyncio.Queue()
+ # Five seconds of mono s16le PCM, split across two queue entries.
+ pcm = b"\x00\x40" * (16000 * 5)
+ queue.put_nowait(pcm[:32000])
+ queue.put_nowait(pcm[32000:])
+ received = asyncio.get_running_loop().create_future()
+ task = asyncio.create_task(
+ transcribe(
+ queue, "", received.set_result, engine="whisper", **options
+ )
+ )
+ try:
+ # Surface constructor errors immediately rather than waiting for a timeout.
+ done, _ = await asyncio.wait(
+ {task, received}, timeout=2, return_when=asyncio.FIRST_COMPLETED
+ )
+ if task in done:
+ await task
+ assert received in done, "Whisper did not deliver the queued transcript"
+ assert received.result() == "Guten Tag"
+ finally:
+ task.cancel()
+ with contextlib.suppress(asyncio.CancelledError):
+ await task
+
+ asyncio.run(exercise())
+ assert loaded_models == [expected_model]
+ assert len(calls) == 1
+ audio, kwargs = calls[0]
+ assert audio.shape == (16000 * 5,)
+ assert audio.dtype == np.float32
+ np.testing.assert_array_equal(audio, 0.5)
+ assert kwargs == {"fp16": False, "language": expected_language}
+
+
+def test_whisper_runner_keeps_bytes_only_contract():
+ from omi.stt import create_transcriber
+
+ chunks = []
+
+ def runner(pcm):
+ chunks.append(pcm)
+ return "custom transcript"
+
+ engine = create_transcriber("whisper", language="de", runner=runner)
+ pcm = b"\x00\x00" * 16
+ assert engine._transcribe_pcm(pcm) == "custom transcript"
+ assert chunks == [pcm]
I have read the issue and confirmed that in sdks/python/omi/stt/whisper.py the transcribe call hardcodes language="en", which blocks callers from passing German or triggering automatic detection. My plan is to add a keyword-only language parameter with a default of "en" to the transcribe wrapper and forward it directly to model.transcribe, matching the acceptance criterion of preserving existing behavior. I can have a PR ready within 24 hours and am starting now.
Hi @josancamon19 @TheoFrk — I have submitted the implementation with hermetic unit tests, documentation, and CI updates in PR #13076. All local tests and repository preflight checks have passed.
Hi @josancamon19, could you clarify the funding status of this contribution? We originally proposed a $50 reward and published the complete implementation, tests, and documentation in this issue before PR #13076 was opened by another contributor. Would you be willing to sponsor our contribution, and how would you handle attribution and payment given the separate PR submission? We understand that no bounty has been approved yet and do not want to assume a payment commitment. Thanks for clarifying.
Hi @TheoFrk @josancamon19 @Git-on-my-level,
Following up on the attribution question:
When I saw the proposed patch here in #13071, I packaged it into PR #13076 to run all local repo preflight checks, wire CI, and add the hermetic tests required for merge.
Full credit to @TheoFrk for the patch design — @TheoFrk was credited as Co-authored-by in the commit metadata from the start, and GitHub reflects both of us as co-authors on PR #13076.
Regarding the proposed $50 sponsorship/bounty, I defer completely to @josancamon19 on how to handle the allocation or split between us. Happy to collaborate and glad to see this landed!
Thanks @Aj2280 for clarifying and crediting my contribution. I'm happy in principle to split any approved sponsorship with you. @josancamon19, could you confirm whether the proposed $50 sponsorship is available and suggest an allocation between us? I understand that funding has not been approved yet; no specific split is assumed at this stage. Thanks to everyone for helping move the contribution forward.
Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏