如何从语音合成 API 获取音频结果?

2023-12-21

The 语音合成API http://updates.html5rocks.com/2014/01/Web-apps-that-talk---Introduction-to-the-Speech-Synthesis-API允许 Chrome Beta 中的文本转语音功能。但是,浏览器会自动播放 TTS 请求的结果。如何访问音频结果进行后处理并禁用 API 的默认行为?


TTS 系统没有标准音频输出,这似乎是故意的,因此不太可能很快改变。

要了解原因,您可以查看此界面的另一侧,其中浏览器扩展可以充当 TTS 引擎并提供客户端可以使用的语音:

Being a 有效的 TTS 引擎 https://developer.chrome.com/extensions/ttsEngineChrome 中此 API 的可访问性是支持启动/暂停/取消和恢复 TTS 请求,并将进度更新作为以下类型的事件发送:

https://developer.chrome.com/extensions/tts#type-TtsEvent https://developer.chrome.com/extensions/tts#type-TtsEvent

因此,除了实际播放之外,TTS 引擎没有标准方法来指示生成的音频。根据具体的TTS引擎,它可能不使用标准的音频格式,甚至浏览器的正常音频设备访问。 (例如,它可能会将文本转发到平台的辅助功能系统。)

If you know something about a specific TTS Engine (or create your own) then you can build your own interface1 to retrieve the audio file. But that TTS Engine must then be installed on every client's browser where you want to use it. This is why any solution must point you to a specific TTS Engine or an outside TTS solution if you want to control the playback beyond adjusting valid inputs to a TTS Engine request (relative pitch, relative volume, relative rate, sex.)

Notes-

1 If you give a TTS Engine such an interface, it can not trivially extend the existing TTS event API since the browser is checking them:

// attempt to add properties to an otherwise legal event in an Engine:
sendTTSev({'type': 'end', 'charIndex': len, foo:'george'});
...
Uncaught Error: Invalid value for argument 2. Property 'foo': Unexpected property.
    at validate (extensions::schemaUtils:34:13)
    at Object.normalizeArgumentsAndValidate  (extensions::schemaUtils:117:3)
    at Object.<anonymous> (extensions::binding:361:30)
    at sendTtsEvent (extensions::ttsEngine:17:22)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从语音合成 API 获取音频结果? 的相关文章

随机推荐