Как выполнить операции TTS с помощью JavaScript?Javascript

Форум по Javascript
Anonymous
Как выполнить операции TTS с помощью JavaScript?

Сообщение Anonymous »

Я следил за этой демонстрацией: https://codepen.io/matt-west/pen/dpmmge
, и это работало с кнопкой, чтобы выбрать голос, но мне нужен конкретный голос, чтобы быть установленным все время.
var firstText = "Starch";

var defaultVoiceName = "Microsoft Hazel - English (United Kingdom)";

if (speechSynthesis) {
} else {
alert("Bad news! Your browser doesn't have the Speech Synthesis API this project requires. Try opening this webpage using the newest version of Google Chrome.");
}

// Create a new instance of SpeechSynthesisUtterance.
var msg = new SpeechSynthesisUtterance();

// Set voice. I'm trying to set needed voice ("Microsoft Hazel - English (United Kingdom)") // here, but it doesn't work. This voice is installed on my machine.
msg.voice = speechSynthesis.getVoices().filter(function(voice) { return voice.name == defaultVoiceName })[0];

// Create a new utterance for the specified text and add it to
// the queue.
function speak(text) {
// Stop the previous tts
window.speechSynthesis.cancel();

// Set the text.
msg.text = text;

// Queue this utterance.
window.speechSynthesis.speak(msg);
}

speak(firstText);
< /code>
Что я здесь делаю не так? Может быть, есть лучший способ что -то? Я попробовал библиотеку "ArpressiveVoice", но она работает с задержкой.

Подробнее здесь: https://stackoverflow.com/questions/796 ... javascript

Вернуться в «Javascript»