Hotword Boosting Implementation for STT Hotword Boosting is a mechanism for increasing the recognition probability of specific words and phrases. Unlike a custom vocabulary (a static list), hotword boosting is applied dynamically at runtime—different phrases for different query contexts. ### Implementation for different providers Google STT with phrase boost:
from google.cloud import speech
def transcribe_with_hotwords(audio_content: bytes, hotwords: list[str]) -> str:
client = speech.SpeechClient()
speech_contexts = [
speech.SpeechContext(
phrases=hotwords,
boost=20.0 # max значение
)
]
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="ru-RU",
speech_contexts=speech_contexts,
enable_automatic_punctuation=True,
)
response = client.recognize(config=config,
audio=speech.RecognitionAudio(content=audio_content))
return response.results[0].alternatives[0].transcript
```**Vosk with grammar (FST-based boosting)**:```python
from vosk import Model, KaldiRecognizer
import json
model = Model("vosk-model-ru-0.42")
# Ограниченная грамматика для определённого контекста
grammar = json.dumps(["да", "нет", "отмена", "помощь", "[unk]"])
recognizer = KaldiRecognizer(model, 16000, grammar)
```**Whisper via prefix prompt** is unreliable, but works for short recordings with specific expectations. ### Dynamic hotwords In voice bots, hotwords depend on the state of the conversation:```python
DIALOG_HOTWORDS = {
"greeting": ["здравствуйте", "добрый день", "привет"],
"payment": ["оплатить", "счёт", "карта", "перевод", "сумма"],
"cancel": ["отменить", "назад", "стоп", "выход"],
}
def get_hotwords_for_state(state: str) -> list[str]:
return DIALOG_HOTWORDS.get(state, [])
```Timeframe: integration into existing STT – 1–2 days.