Chromium支持語音合成API嗎?
是的,Web Speech API具有在Chromium瀏覽器的基本支持,但也有既鉻和Firefox實施規範的幾個問題,看的見Blink>Speech,Internals>SpeechSynthesis,Web Speech。
我需要安裝聲音嗎?如果是這樣,我該怎麼做?我正在使用 Fedora。是聲音像視頻,我需要安裝額外的包 它的工作?
是的,需要安裝聲音。鉻未附帶聲音默認設置爲SpeechSynthesisUtterance
voice
屬性,請參閱How to use Web Speech API at chromium?; How to capture generated audio from window.speechSynthesis.speak() call?。
您可以安裝speech-dispatcher
作爲系統語音合成服務器的服務器和espeak
作爲語音合成器。
$ yum install speech-dispatcher espeak
您也可以在用戶的主文件夾設置配置文件speech-dispatcher
設置兩個speech-dispatcher
特定選項和輸出模塊,您的使用,例如espeak
$ spd-conf -u
啓動鉻與--enable-speech-dispatcher
標誌會自動生成到speech-dispatcher
的連接,您可以在0
和5
之間設置LogLevel
以檢查Chromium代碼和speech-dispatcher
之間的SSIP通信。
.getVoices()
返回異步結果,需要被調用兩次
看到這個electron
問題在GitHub上Speech Synthesis: No Voices #586。
window.speechSynthesis.onvoiceschanged = e => {
const voices = window.speechSynthesis.getVoices();
// do speech synthesis stuff
console.log(voices);
}
window.speechSynthesis.getVoices();
或作爲與價值是聲音
(async() => {
const getVoices = (voiceName = "") => {
return new Promise(resolve => {
window.speechSynthesis.onvoiceschanged = e => {
// optionally filter returned voice by `voiceName`
// resolve(
// window.speechSynthesis.getVoices()
// .filter(({name}) => /^en.+whisper/.test(name))
//);
resolve(window.speechSynthesis.getVoices());
}
window.speechSynthesis.getVoices();
})
}
const voices = await getVoices();
console.log(voices);
})();
大的陣列返回
Promise
異步函數組成的,非常感謝你的解釋。將測試並標記您的解決方案,並在工作時加註,這可能會。 – jcubic@jcubic另請參見https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis/cancel – guest271314
安裝語音調度程序和espeak足以使鉻語言工作,例如'spd-conf - ü'我有錯誤,找不到命令,當啓動鉻時,'--enable-speech-dispatcher'選項顯示關於不支持標誌的錯誤。 – jcubic