Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Tencent ASR: leave out hotwords Tencent cannot take; list the connector in the docs

Murtaza Nasirafc9407ee5dd
diff --git a/docs/advanced/custom-connectors.md b/docs/advanced/custom-connectors.md
index 251be918..2ae87ec6 100644
--- a/docs/advanced/custom-connectors.md
+++ b/docs/advanced/custom-connectors.md
@@ -541,9 +541,10 @@ If you create a connector for a popular provider, consider contributing it back
Popular providers we'd love to see connectors for:
- Deepgram
-- AssemblyAI
- Google Cloud Speech-to-Text
- Amazon Transcribe
- ~~Azure Speech Services~~ → **Azure OpenAI connector now available (experimental, v0.8.6+)**
- ~~Mistral Voxtral~~ → **Mistral connector now available**
- ~~VibeVoice ASR~~ → **VibeVoice connector now available (self-hosted via vLLM)**
+- ~~AssemblyAI~~ → **AssemblyAI connector now available**
+- ~~Tencent Cloud ASR~~ → **Tencent Cloud connector now available ([setup](tencent-asr.md))**
diff --git a/docs/advanced/tencent-asr.md b/docs/advanced/tencent-asr.md
index b6d42108..8b43fbc6 100644
--- a/docs/advanced/tencent-asr.md
+++ b/docs/advanced/tencent-asr.md
@@ -28,9 +28,11 @@ engine, not the UI language hint. Speaker count hints are not supported by these
16 kHz engines. Segments include sentence timestamps and anonymous speaker labels;
this does not identify people's names.
-Comma-separated UI hotwords are sent with weight 5 (up to 128 words, at most
-30 UTF-8 bytes each). Alternatively set `TENCENT_ASR_HOTWORD_ID` to a Tencent
-hotword table ID. Request hotwords take precedence. Optional
+Comma-separated UI hotwords are sent with weight 5. Tencent accepts up to 128
+words of at most 30 UTF-8 bytes each (10 Chinese characters), without `|`;
+other words are left out of the request and noted in the log. Alternatively set
+`TENCENT_ASR_HOTWORD_ID` to a Tencent hotword table ID. Request hotwords take
+precedence. Optional
`TENCENT_ASR_TIMEOUT=1800` and `TENCENT_ASR_POLL_INTERVAL=5` control polling
in seconds (maximum timeout 10800).
diff --git a/src/services/transcription/connectors/tencent_asr.py b/src/services/transcription/connectors/tencent_asr.py
index c08e99d6..e0f8a49f 100644
--- a/src/services/transcription/connectors/tencent_asr.py
+++ b/src/services/transcription/connectors/tencent_asr.py
@@ -105,12 +105,18 @@ class TencentASRConnector(BaseTranscriptionConnector):
model = request.model if request.model in MODELS else self.model
params = {'EngineModelType': model, 'ChannelNum': 1, 'ResTextFormat': 3,
'SpeakerDiarization': int(request.diarize or model == MODELS[0])}
+ words = []
if request.hotwords:
- words = list(dict.fromkeys(w.strip() for w in request.hotwords.split(',') if w.strip()))
- if len(words) > 128 or any(len(w) > 30 or len(w.encode('utf-8')) > 30 or '|' in w for w in words):
- raise ConfigurationError('Tencent hotwords: at most 128 words, 30 UTF-8 bytes per word; no | characters')
- if words:
- params['HotwordList'] = ','.join(w + '|5' for w in words)
+ given = list(dict.fromkeys(w.strip() for w in request.hotwords.split(',') if w.strip()))
+ # Tencent rejects the whole task for one word it cannot take, and
+ # the same hotwords are used with every connector, so those words
+ # are left out of the request.
+ words = [w for w in given if len(w.encode('utf-8')) <= 30 and '|' not in w][:128]
+ if len(words) < len(given):
+ logger.warning('Tencent ASR: %d of %d hotwords left out (at most 128 words, '
+ '30 UTF-8 bytes per word, no | characters)', len(given) - len(words), len(given))
+ if words:
+ params['HotwordList'] = ','.join(w + '|5' for w in words)
elif self.hotword_id:
params['HotwordId'] = self.hotword_id
return params
diff --git a/tests/test_tencent_asr.py b/tests/test_tencent_asr.py
index 27cb61ab..cf58eace 100644
--- a/tests/test_tencent_asr.py
+++ b/tests/test_tencent_asr.py
@@ -75,10 +75,19 @@ def test_invalid_config(config):
mod.TencentASRConnector(config)
[email protected]('words', ['a|100', '中' * 11, ','.join(str(i) for i in range(129))])
-def test_invalid_hotwords(connector, words):
- with pytest.raises(ConfigurationError):
- connector._parameters(request(hotwords=words))
[email protected]('words, kept', [
+ ('a|100,alpha', 'alpha|5'),
+ ('中' * 11 + ',' + '中' * 10, '中' * 10 + '|5'),
+ (','.join(str(i) for i in range(129)), ','.join(f'{i}|5' for i in range(128)))])
+def test_hotwords_tencent_cannot_take_are_left_out(connector, words, kept):
+ assert connector._parameters(request(hotwords=words))['HotwordList'] == kept
+
+
+def test_hotword_table_used_when_no_request_hotword_fits():
+ connector = mod.TencentASRConnector({'secret_id': 'test-id', 'secret_key': 'test-secret',
+ 'hotword_id': 'table-1'})
+ params = connector._parameters(request(hotwords='a|1'))
+ assert 'HotwordList' not in params and params['HotwordId'] == 'table-1'
def test_quota_error_no_secrets(connector, monkeypatch):