mirror of
https://github.com/chliny/hass-tencentcloud-asr.git
synced 2026-07-31 14:03:55 +08:00
feat: add ASR filtering options
This commit is contained in:
@@ -10,7 +10,15 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from .tencentcloud_api import TencentCloudAsrAPi
|
||||
from .tencentcloud_api import ModuleSupportLanguage
|
||||
from .tencentcloud_api import DefaultModel
|
||||
from . import SecretIdKey, SecretKeyKey, ModelKey
|
||||
from . import (
|
||||
ConvertNumModeKey,
|
||||
FilterDirtyKey,
|
||||
FilterModalKey,
|
||||
FilterPuncKey,
|
||||
ModelKey,
|
||||
SecretIdKey,
|
||||
SecretKeyKey,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -32,6 +40,7 @@ class ASRSTT(stt.SpeechToTextEntity):
|
||||
self._attr_unique_id = f"tencentcloud_asr_stt"
|
||||
self._attr_name = f"TencentCloud Asr STT"
|
||||
self.hass = hass
|
||||
self.config_entry = config_entry
|
||||
|
||||
@property
|
||||
def supported_languages(self) -> list[str]:
|
||||
@@ -71,9 +80,25 @@ class ASRSTT(stt.SpeechToTextEntity):
|
||||
audio += chunk
|
||||
|
||||
data = base64.b64encode(audio).decode("utf8", "ignore").strip()
|
||||
model: str = self.hass.data.get(ModelKey, DefaultModel)
|
||||
_LOGGER.debug(f"process_audio_stream transcribe: {data} {model}")
|
||||
ret, result = await self.hass.async_add_executor_job(partial(self.tencentCloudApi.SentenceRecognition, model, data))
|
||||
config = {**self.config_entry.data, **self.config_entry.options}
|
||||
model: str = config.get(ModelKey, DefaultModel)
|
||||
_LOGGER.debug(
|
||||
"process_audio_stream transcribe: audio_bytes=%s model=%s",
|
||||
len(audio),
|
||||
model,
|
||||
)
|
||||
ret, result = await self.hass.async_add_executor_job(
|
||||
partial(
|
||||
self.tencentCloudApi.SentenceRecognition,
|
||||
model,
|
||||
data,
|
||||
len(audio),
|
||||
config.get(FilterDirtyKey, "0"),
|
||||
config.get(FilterModalKey, False),
|
||||
config.get(FilterPuncKey, False),
|
||||
config.get(ConvertNumModeKey, True),
|
||||
)
|
||||
)
|
||||
if not ret:
|
||||
return stt.SpeechResult(result, stt.SpeechResultState.ERROR)
|
||||
if not result:
|
||||
|
||||
Reference in New Issue
Block a user