Assistant answers general questions and stays silent for overheard talk ("Ignored." is not said); stt prompt setting sent as the transcription prompt
Docs / docs (push) Successful in 39s
Playwright Tests / test-playwright (1, 2) (push) Successful in 4m26s
Playwright Tests / test-playwright (2, 2) (push) Successful in 2m25s
pre-commit / pre-commit (push) Successful in 3m24s
Test Backend / test-backend (3.12) (push) Successful in 6m3s
Test Backend / test-backend (3.14) (push) Successful in 5m41s
Compose Smoke Test / test-compose (push) Successful in 35s
Playwright Tests / merge-reports (push) Successful in 1m20s

This commit is contained in:
Melvin Strobl
2026-11-06 07:27:44 +01:00
parent 4c15f4abe1
commit 261cf1ec2a
6 changed files with 93 additions and 24 deletions
+16 -8
View File
@@ -194,12 +194,19 @@ async def transcribe(
*,
model: str = "whisper-1",
timeout: float = 30.0,
prompt: str = "",
) -> str:
"""``POST {api_base}/audio/transcriptions``: a whole clip, and what it says."""
"""``POST {api_base}/audio/transcriptions``: a whole clip, and what it says.
``prompt`` is words the clip is likely to hold, such as room names.
"""
data = {"model": model, "response_format": "json"}
if prompt:
data["prompt"] = prompt
response = await _client(api_base).post(
api_base.rstrip("/") + "/audio/transcriptions",
files={"file": (filename, audio, media_type)},
data={"model": model, "response_format": "json"},
data=data,
timeout=timeout,
)
if response.is_error:
@@ -236,25 +243,26 @@ async def transcribe_stream(
*,
rate: int = 16000,
idle_s: float = 10.0,
prompt: str = "",
) -> AsyncIterator[tuple[bool, str]]:
"""``WS {api_base}/realtime``: one utterance, transcribed while it is spoken.
Sends each chunk of PCM16 taken off ``audio`` and commits at ``None``.
Yields ``(False, delta)`` as words are agreed on, then ``(True,
transcript)`` once. A chunk that takes longer than ``idle_s`` to come
raises ``TimeoutError``, so an utterance nobody commits ends.
raises ``TimeoutError``, so an utterance nobody commits ends. ``prompt``
is words the speech is likely to hold, as for ``transcribe``.
"""
url = "ws" + api_base.rstrip("/").removeprefix("http") + "/realtime"
async with connect(url, open_timeout=idle_s) as ws:
update = {"type": "audio/pcm", "rate": rate}
given: dict[str, Any] = {"format": {"type": "audio/pcm", "rate": rate}}
if prompt:
given["transcription"] = {"prompt": prompt}
await ws.send(
json.dumps(
{
"type": "session.update",
"session": {
"type": "transcription",
"audio": {"input": {"format": update}},
},
"session": {"type": "transcription", "audio": {"input": given}},
}
)
)