Class SpeechConfig

定义语音/意向识别或语音合成的配置的类。

成员

EmbeddedSpeechConfig

语法:public friend EmbeddedSpeechConfig;

HybridSpeechConfig

语法:public friend HybridSpeechConfig;

运算符 SPXSPEECHCONFIGHANDLE

语法:public inline explicit operator SPXSPEECHCONFIGHANDLE ( ) const;

用于获取基础句柄值的内部运算符。

退货

句柄。

SetSpeechRecognitionLanguage

语法:public inline void SetSpeechRecognitionLanguage ( const std::string & lang );

将输入语言设置为语音识别器。

参数

  • lang 指定要以 BCP-47 格式识别的口语的名称。

GetSpeechRecognitionLanguage

语法:public inline std::string GetSpeechRecognitionLanguage ( ) const;

获取语音识别的输入语言。 语言以 BCP-47 格式指定。

退货

语音识别语言。

SetSpeechSynthesisLanguage

语法:public inline void SetSpeechSynthesisLanguage ( const std::string & lang );

设置语音合成器的语言。 在版本 1.4.0 中添加。

参数

  • lang 指定语言的名称(例如 en-US)

GetSpeechSynthesisLanguage

语法:public inline std::string GetSpeechSynthesisLanguage ( ) const;

获取语音合成器的语言。 在版本 1.4.0 中添加。

退货

语音合成语言。

SetSpeechSynthesisVoiceName

语法:public inline void SetSpeechSynthesisVoiceName ( const std::string & voiceName );

设置语音合成器的声音。 在版本 1.4.0 中添加。

参数

  • voiceName 指定语音名称

GetSpeechSynthesisVoiceName

语法:public inline std::string GetSpeechSynthesisVoiceName ( ) const;

获取语音合成器的声音。 在版本 1.4.0 中添加。

退货

语音合成语音名称。

SetSpeechSynthesisOutputFormat

语法:public inline void SetSpeechSynthesisOutputFormat ( SpeechSynthesisOutputFormat formatId );

设置语音合成输出格式(例如 Riff16Khz16BitMonoPcm)。 在版本 1.4.0 中添加。

参数

  • formatId 指定输出格式 ID

GetSpeechSynthesisOutputFormat

语法:public inline std::string GetSpeechSynthesisOutputFormat ( ) const;

获取语音合成输出格式。 在版本 1.4.0 中添加。

退货

语音合成输出格式。

SetEndpointId

语法:public inline void SetEndpointId ( const std::string & endpointId );

设置自定义语音或自定义语音的终结点 ID。

参数

  • endpointId 终结点 ID。

GetEndpointId

语法:public inline std::string GetEndpointId ( ) const;

获取自定义语音或自定义语音的终结点 ID。

退货

终结点 ID。

SetAuthorizationToken

语法:public inline void SetAuthorizationToken ( const std::string & token );

设置要连接到服务的授权令牌。 注意:调用方需要确保授权令牌有效。 在授权令牌过期之前,调用方需要使用新的有效令牌调用此 setter 来刷新它。 创建新识别器时复制配置值时,新令牌值将不适用于已创建的识别器。 对于以前创建的识别器,需要设置相应识别器的授权令牌以刷新令牌。 否则,识别器会在识别过程中遇到错误。

参数

  • token 授权令牌。

GetAuthorizationToken

语法:public inline std::string GetAuthorizationToken ( ) const;

获取要连接到服务的授权令牌。

退货

授权令牌。

GetSubscriptionKey

语法:public inline std::string GetSubscriptionKey ( ) const;

获取用于创建语音识别器或意向识别器或翻译识别器或语音合成器的订阅密钥。

退货

订阅密钥。

GetRegion

语法:public inline std::string GetRegion ( ) const;

获取用于创建语音识别器或意向识别器或翻译识别器或语音合成器的区域键。

退货

地区。

GetOutputFormat

语法:public inline OutputFormat GetOutputFormat ( ) const;

获取语音识别输出格式(简单或详细)。 注意:此输出格式用于语音识别结果,请使用 SpeechConfig::GetSpeechSynthesisOutputFormat 获取合成的音频输出格式。

退货

语音识别输出格式。

SetOutputFormat

语法:public inline void SetOutputFormat ( OutputFormat format );

设置语音识别输出格式(简单或详细)。 注意:此输出格式用于语音识别结果,请使用 SpeechConfig::SetSpeechSynthesisOutputFormat 设置合成的音频输出格式。

参数

  • format 语音识别输出格式

SetProfanity

语法:public inline void SetProfanity ( ProfanityOption profanity );

设置不雅内容选项。 在版本 1.5.0 中添加。

参数

  • profanity 不雅选项值。

EnableAudioLogging

语法:public inline void EnableAudioLogging ( );

启用服务中的音频日志记录。 在版本 1.5.0 中添加。

音频和内容日志存储在Microsoft拥有的存储中,或存储在链接到认知服务订阅(启用自带存储(BYOS)的语音资源)的自己的存储帐户中。

RequestWordLevelTimestamps

语法:public inline void RequestWordLevelTimestamps ( );

在响应结果中包含字级时间戳。 在版本 1.5.0 中添加。

EnableDictation

语法:public inline void EnableDictation ( );

启用听写模式。 仅在语音识别中受支持。 在版本 1.5.0 中添加。

SetProxy

语法:public inline void SetProxy ( const std::string & proxyHostName , uint32_t proxyPort , const std::string & proxyUserName , const std::string & proxyPassword );

设置在版本 1.1.0 中添加的代理配置。

注意:macOS 上不提供代理功能。 此函数对此平台不起作用。

参数

  • proxyHostName 代理服务器的主机名,而不使用协议方案([http://](http://)

  • proxyPort 代理服务器的端口号

  • proxyUserName 代理服务器的用户名

  • proxyPassword 代理服务器的密码

SetProperty

语法:public inline void SetProperty ( const std::string & name , const std::string & value );

按名称设置属性值。

参数

  • name 属性名称。

  • value 属性值。

GetProperty

语法:public inline std::string GetProperty ( const std::string & name ) const;

按名称获取属性值。

参数

  • name 参数名称。

退货

属性值。

GetProperty

语法:public inline std::string GetProperty ( PropertyId id ) const;

按 ID 获取属性值。

参数

  • id 参数 ID。

退货

属性值。

SetProperty

语法:public inline void SetProperty ( PropertyId id , const std::string & value );

按 ID 设置属性值。

参数

  • id 属性 ID。

  • value 属性值。

SetServiceProperty

语法:public inline void SetServiceProperty ( const std::string & name , const std::string & value , ServicePropertyChannel channel );

设置将使用指定通道传递给服务的属性值。 在版本 1.5.0 中添加。

参数

  • name 属性名称。

  • value 属性值。

  • channel 用于将指定属性传递给服务的通道。

~SpeechConfig

语法:public inline virtual ~SpeechConfig ( );

析构对象。

FromSubscription

语法:public inline static std::shared_ptr< SpeechConfig > FromSubscription ( const std::string & subscription , const std::string & region );

使用指定的订阅密钥和区域创建语音配置的实例。

参数

  • subscription 订阅密钥。

  • region 区域名称(请参阅 区域页面)。

退货

指向新语音配置实例的共享指针。

FromAuthorizationToken

语法:public inline static std::shared_ptr< SpeechConfig > FromAuthorizationToken ( const std::string & authToken , const std::string & region );

使用指定的授权令牌和区域创建语音配置的实例。 注意:调用方需要确保授权令牌有效。 在授权令牌过期之前,调用方需要使用新的有效令牌调用此 setter 来刷新它。 创建新识别器时复制配置值时,新令牌值将不适用于已创建的识别器。 对于以前创建的识别器,需要设置相应识别器的授权令牌以刷新令牌。 否则,识别器会在识别过程中遇到错误。

参数

  • authToken 授权令牌。

  • region 区域名称(请参阅 区域页面)。

退货

指向新语音配置实例的共享指针。

FromEndpoint

语法:public inline static std::shared_ptr< SpeechConfig > FromEndpoint ( const std::string & endpoint , const std::string & subscription );

使用指定的终结点和订阅创建语音配置的实例。 此方法仅适用于使用非标准服务终结点的用户。 注意:终结点 URI 中指定的查询参数不会更改,即使这些参数是由任何其他 API 设置的。 例如,如果识别语言在 URI 中定义为查询参数“language=de-DE”,并且还由 SetSpeechRecognitionLanguage(“en-US”),URI 中的语言设置优先,并且有效语言为“de-DE”。 只有未在终结点 URI 中指定的参数才能由其他 API 设置。 注意:若要将授权令牌用于 FromEndpoint,请使用 FromEndpoint(const SPXSTRING&),然后在创建的 SpeechConfig 实例上调用 SetAuthorizationToken()。

参数

  • endpoint 要连接到的服务终结点。

  • subscription 订阅密钥。

退货

指向新语音配置实例的共享指针。

FromEndpoint

语法:public inline static std::shared_ptr< SpeechConfig > FromEndpoint ( const std::string & endpoint );

创建具有指定终结点的 SpeechConfig 实例。 此方法仅适用于使用非标准服务终结点的用户。 注意:终结点 URI 中指定的查询参数不会更改,即使这些参数是由任何其他 API 设置的。 是否支持特定查询参数,取决于终结点和方案。 例如,如果识别语言在 URI 中定义为查询参数“language=de-DE”,并且还由 SetSpeechRecognitionLanguage(“en-US”),URI 中的语言设置优先,并且有效语言为“de-DE”。 仅当终结点和方案组合支持语言作为查询参数时,该示例才适用。 只有未在终结点 URI 中指定的参数才能由其他 API 设置。 注意:如果终结点需要订阅密钥进行身份验证,请使用 FromEndpoint(const SPXSTRING&、const SPXSTRING&)将订阅密钥作为参数传递。 若要将授权令牌用于 FromEndpoint,请使用此方法创建 SpeechConfig 实例,然后在创建的 SpeechConfig 实例上调用 SetAuthorizationToken()。 注意:在版本 1.5.0 中添加。

参数

  • endpoint 要连接到的服务终结点 URI。

退货

指向新语音配置实例的共享指针。

FromHost

语法:public inline static std::shared_ptr< SpeechConfig > FromHost ( const std::string & host , const std::string & subscription );

使用指定的主机和订阅创建语音配置的实例。 此方法仅适用于使用非默认服务主机的用户。 将假定标准资源路径。 对于具有非标准资源路径或根本没有路径的服务,请改用 FromEndpoint。 注意:主机 URI 中不允许查询参数,并且必须由其他 API 设置。 注意:若要将授权令牌用于 FromHost,请使用 FromHost(const SPXSTRING&),然后在创建的 SpeechConfig 实例上调用 SetAuthorizationToken()。 注意:在版本 1.8.0 中添加。

参数

  • host 要连接到的服务主机。 格式为“protocol://host:port”,其中“:p ort”是可选的。

  • subscription 订阅密钥。

退货

指向新语音配置实例的共享指针。

FromHost

语法:public inline static std::shared_ptr< SpeechConfig > FromHost ( const std::string & host );

创建具有指定主机的 SpeechConfig 实例。 此方法仅适用于使用非默认服务主机的用户。 将假定标准资源路径。 对于具有非标准资源路径或根本没有路径的服务,请改用 FromEndpoint。 注意:主机 URI 中不允许查询参数,并且必须由其他 API 设置。 注意:如果主机需要订阅密钥进行身份验证,请使用 FromHost(const SPXSTRING&、const SPXSTRING&)将订阅密钥作为参数传递。 若要将授权令牌用于 FromHost,请使用此方法创建 SpeechConfig 实例,然后在创建的 SpeechConfig 实例上调用 SetAuthorizationToken()。 注意:在版本 1.8.0 中添加。

参数

  • host 要连接到的服务主机 URI。 格式为“protocol://host:port”,其中“:p ort”是可选的。

退货

指向新语音配置实例的共享指针。