我已经尝试寻找答案了好几个星期了,我确实需要帮助,所以请回答。我正在使用一个简单的聊天机器人,一切正常,但是我想使用语音合成将en-US Male口音更改为en-IN Male。我已经尝试了所有内容,但这只是行不通。我已经成功控制台。记录了我计算机中可用的声音,看起来好像我没有en-IN,但我确实有en-GB和20种其他声音。我试过使用识别。lang ='en-IN';但这没有用,我也尝试在en-IN上使用双引号,并尝试使用en_IN。我还尝试了十亿其他事情,但这不会改变其口音。我需要在明天之前完成此工作,我真的将感谢任何尝试帮助我的人。另外,我的脚本标签位于内部,而不位于外部。
const btn = document.querySelector('.talk');
const content = document.querySelector('.content');
const greetings = [
'If you are good im good too.',
'Im doin alright',
'doing well.'
];
const weather = [
'Ask the weatherman!',
'I recommend checking your phone or the news '
];
const name = [
'My name is techwaala',
'its techwaala, because I love to code!'
];
const hello = [
'Why hello! How are you doing today?',
'Hey there How are you?'
];
const hru = [
'Happy to hear that!',
'Im so sorry to hear that',
'Feel better soon!'
];
const color = [
'oooh that\'s a hard one, I have a lot of favorites.',
'I have so many!'
];
const SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.lang = 'en-IN';
recognition.onstart = function() {
console.log('voice is activated speak into the mic');
};
const voiceschanged = () => {
console.log(`Voices #: ${speechSynthesis.getVoices().length}`)
speechSynthesis.getVoices().forEach(voice => {
console.log(voice.name, voice.lang)
})
}
speechSynthesis.onvoiceschanged = voiceschanged
recognition.onresult = function(event) {
const current = event.resultIndex;
const transcript = event.results[current][0].transcript;
content.textContent = transcript;
readOutLoud(transcript);
}
btn.addEventListener('click', () => {
recognition.start();
});
function readOutLoud(message) {
const speech = new SpeechSynthesisUtterance();
speech.text = 'I dont know what you said';
if(message.includes('how are you')) {
const finalText =
greetings[Math.floor(Math.random() * greetings.length)];
speech.text = finalText;
}
if(['hey', 'hi', 'hello', 'hi there', 'hey there', 'hi techwala', 'hey techwala','hello techwala']
.some(word => message.includes(word))) {
const finalText = hello[Math.floor(Math.random() * hello.length)];
speech.text = finalText;
}
if(['whats your name', 'your name']
.some(word => message.includes(word))) {
const finalText = name[Math.floor(Math.random() * name.length)];
speech.text = finalText;
}
if(['how\'s the weather', 'what\'s the weather like', 'is it sunny', 'is it raining', 'is it cloudy', 'is it snowing', 'what\'s the weather']
.some(word => message.includes(word))) {
const finalText = weather[Math.floor(Math.random() * weather.length)];
speech.text = finalText;
}
if(['I/m doing good', 'doing good', 'I\'m doing well', 'same old', 'I\'m fine', 'I\'m doing fine']
.some(word => message.includes(word))) {
const finalText = hru[0];
speech.text = finalText;
}
if(['what\'s your favorite color', 'what color do you like', 'favorite color', 'do you have a favorite color']
.some(word => message.includes(word))) {
const finalText = color[0];
speech.text = finalText;
}
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button class="talk">Talk</button>
<h3 class="content"></h3>
</body>
</html>