For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /developers/core/entity/stt.md.

语音转文字实体

Speech-to-text (STT) 实体允许其他集成或应用程序向 STT API 流式传输语音数据并获取文本。

Speech-to-text 实体派生自 homeassistant.components.stt.SpeechToTextEntity

属性

Tip

属性应始终仅返回内存中的信息,而不是执行 I/O(如网络请求)。

名称类型默认值描述
supported_languageslist[str]必填STT 服务支持的语言。
supported_formatslist[AudioFormats]必填STT 服务支持的音频格式,wav 或 ogg。
supported_codecslist[AudioCodecs]必填STT 服务支持的音频编解码器,pcm 或 opus。
supported_bit_rateslist[AudioBitRates]必填STT 服务支持的音频比特率,8、16、24 或 32。
supported_sample_rateslist[AudioSampleRates]必填STT 服务支持的音频采样率。
supported_channelslist[AudioChannels]必填STT 服务支持的音频声道,1 或 2。

方法

处理音频流

处理音频流方法用于向 STT 服务发送音频并获取文本。

class MySpeechToTextEntity(SpeechToTextEntity):
    """Represent a Speech To Text entity."""

    async def async_process_audio_stream(
        self, metadata: SpeechMetadata, stream: AsyncIterable[bytes]
    ) -> SpeechResult:
        """Process an audio stream to STT service.

        Only streaming content is allowed!
        """