SpeechRecognizer class
从麦克风、文件或其他音频输入流执行语音识别,并因此获取转录的文本。
- 扩展
构造函数
Speech |
SpeechRecognizer 构造函数。 |
属性
authorization |
获取用于与服务通信的授权令牌。 |
canceled | 事件已取消,表明识别过程中发生了错误。 |
endpoint |
获取用于语音识别的自定义语音模型的终结点 ID。 |
internal |
|
output |
获取识别的输出格式。 |
properties | 为此 SpeechRecognizer 定义的属性及其值的集合。 |
recognized | 事件识别的信号是收到最终识别结果。 |
recognizing | 事件识别信号表明收到中间识别结果。 |
speech |
获取识别的口语。 |
telemetry |
此方法返回遥测设置的当前状态。 |
继承属性
session |
定义会话启动事件的事件处理程序。 |
session |
定义会话停止事件的事件处理程序。 |
speech |
定义语音停止事件的事件处理程序。 |
speech |
定义语音启动事件的事件处理程序。 |
方法
close(() => void, (error: string) => void) | 关闭此类实例持有的所有外部资源。 |
dispose(boolean) | 释放对象持有的任何资源。 |
From |
SpeechRecognizer 构造函数。 |
recognize |
启动语音识别,并在识别第一个话语后停止。 任务返回识别文本作为结果。 注意:RecognizeOnceAsync() 在识别第一个话语时返回,因此它仅适用于单次识别(如命令或查询)。 对于长时间运行的识别,请改用 StartContinuousRecognitionAsync()。 |
start |
启动语音识别,直到调用 stopContinuousRecognitionAsync()。 用户必须订阅事件才能接收识别结果。 |
start |
使用关键字发现启动语音识别,直到调用 stopKeywordRecognitionAsync()。 用户必须订阅事件才能接收识别结果。 注意:关键词发现功能仅在语音设备 SDK 上可用。 此功能当前不包括在 SDK 本身中。 |
stop |
停止连续语音识别。 |
stop |
停止连续语音识别。 注意:关键词发现功能仅在语音设备 SDK 上可用。 此功能当前不包括在 SDK 本身中。 |
继承的方法
enable |
此方法全局启用或禁用遥测。 |
构造函数详细信息
SpeechRecognizer(SpeechConfig, AudioConfig)
SpeechRecognizer 构造函数。
new SpeechRecognizer(speechConfig: SpeechConfig, audioConfig?: AudioConfig)
参数
- speechConfig
- SpeechConfig
此识别器的初始属性集
- audioConfig
- AudioConfig
与识别器关联的可选音频配置
属性详细信息
authorizationToken
获取用于与服务通信的授权令牌。
string authorizationToken
属性值
string
授权令牌。
canceled
事件已取消,表明识别过程中发生了错误。
public canceled: (sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void
属性值
(sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void
endpointId
获取用于语音识别的自定义语音模型的终结点 ID。
string endpointId
属性值
string
用于语音识别的自定义语音模型的终结点 ID。
internalData
object internalData
属性值
object
outputFormat
properties
为此 SpeechRecognizer 定义的属性及其值的集合。
PropertyCollection properties
属性值
为此 SpeechRecognizer 定义的属性及其值的集合。
recognized
事件识别的信号是收到最终识别结果。
public recognized: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void
属性值
(sender: Recognizer, event: SpeechRecognitionEventArgs) => void
recognizing
事件识别信号表明收到中间识别结果。
public recognizing: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void
属性值
(sender: Recognizer, event: SpeechRecognitionEventArgs) => void
speechRecognitionLanguage
获取识别的口语。
string speechRecognitionLanguage
属性值
string
识别的口语。
telemetryEnabled
此方法返回遥测设置的当前状态。
static boolean telemetryEnabled
属性值
boolean
如果启用遥测数据,则为 true;否则为 false。
继承属性详细信息
sessionStarted
定义会话启动事件的事件处理程序。
public sessionStarted: (sender: Recognizer, event: SessionEventArgs) => void
属性值
(sender: Recognizer, event: SessionEventArgs) => void
sessionStopped
定义会话停止事件的事件处理程序。
public sessionStopped: (sender: Recognizer, event: SessionEventArgs) => void
属性值
(sender: Recognizer, event: SessionEventArgs) => void
speechEndDetected
定义语音停止事件的事件处理程序。
public speechEndDetected: (sender: Recognizer, event: RecognitionEventArgs) => void
属性值
(sender: Recognizer, event: RecognitionEventArgs) => void
speechStartDetected
定义语音启动事件的事件处理程序。
public speechStartDetected: (sender: Recognizer, event: RecognitionEventArgs) => void
属性值
(sender: Recognizer, event: RecognitionEventArgs) => void
方法详细信息
close(() => void, (error: string) => void)
关闭此类实例持有的所有外部资源。
function close(cb?: () => void, errorCb?: (error: string) => void)
参数
- cb
-
() => void
- errorCb
-
(error: string) => void
dispose(boolean)
释放对象持有的任何资源。
function dispose(disposing: boolean): Promise<void>
参数
- disposing
-
boolean
如果释放对象,则为 true。
返回
Promise<void>
FromConfig(SpeechConfig, AutoDetectSourceLanguageConfig, AudioConfig)
SpeechRecognizer 构造函数。
static function FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): SpeechRecognizer
参数
- speechConfig
- SpeechConfig
此识别器的初始属性集
- autoDetectSourceLanguageConfig
- AutoDetectSourceLanguageConfig
与识别器关联的源语言检测配置
- audioConfig
- AudioConfig
与识别器关联的可选音频配置
返回
recognizeOnceAsync((e: SpeechRecognitionResult) => void, (e: string) => void)
启动语音识别,并在识别第一个话语后停止。 任务返回识别文本作为结果。 注意:RecognizeOnceAsync() 在识别第一个话语时返回,因此它仅适用于单次识别(如命令或查询)。 对于长时间运行的识别,请改用 StartContinuousRecognitionAsync()。
function recognizeOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void)
参数
- cb
-
(e: SpeechRecognitionResult) => void
接收 SpeechRecognitionResult 的回调。
- err
-
(e: string) => void
发生错误时调用的回调。
startContinuousRecognitionAsync(() => void, (e: string) => void)
启动语音识别,直到调用 stopContinuousRecognitionAsync()。 用户必须订阅事件才能接收识别结果。
function startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void)
参数
- cb
-
() => void
识别启动后调用的回调。
- err
-
(e: string) => void
发生错误时调用的回调。
startKeywordRecognitionAsync(KeywordRecognitionModel, () => void, (e: string) => void)
使用关键字发现启动语音识别,直到调用 stopKeywordRecognitionAsync()。 用户必须订阅事件才能接收识别结果。 注意:关键词发现功能仅在语音设备 SDK 上可用。 此功能当前不包括在 SDK 本身中。
function startKeywordRecognitionAsync(model: KeywordRecognitionModel, cb?: () => void, err?: (e: string) => void)
参数
- model
- KeywordRecognitionModel
指定要识别的关键字的关键字识别模型。
- cb
-
() => void
识别启动后调用的回调。
- err
-
(e: string) => void
发生错误时调用的回调。
stopContinuousRecognitionAsync(() => void, (e: string) => void)
停止连续语音识别。
function stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void)
参数
- cb
-
() => void
识别停止后调用回调。
- err
-
(e: string) => void
发生错误时调用的回调。
stopKeywordRecognitionAsync(() => void)
停止连续语音识别。 注意:关键词发现功能仅在语音设备 SDK 上可用。 此功能当前不包括在 SDK 本身中。
function stopKeywordRecognitionAsync(cb?: () => void)
参数
- cb
-
() => void
识别停止后调用回调。
继承的方法详细信息
enableTelemetry(boolean)
此方法全局启用或禁用遥测。
static function enableTelemetry(enabled: boolean)
参数
- enabled
-
boolean
遥测收集的全局设置。 如果设置为 true,则收集遥测信息(如麦克风错误)并将其发送到Microsoft。 如果设置为 false,则不会向Microsoft发送任何遥测数据。