我已经问了很多这个问题,但没有得到很好的答案,所以请帮助我。
我目前正在开发一个运行良好的聊天机器人,唯一的问题是我想将口音更改为印度男性,但默认值为美国男性。
我尝试使用 HTML lang = 'en-IN' (插入时它在标签中),但这没有用,所以我尝试在 const 识别之后放置recognition.lang = 'en-IN',但这也不起作用. 我的最后一次尝试是使用 responisvevoice.org,这很简单。我只是复制了他们给我的链接并粘贴了它,但这也没有用!我确信仅仅粘贴他们给我的链接不会神奇地改变我聊天机器人的口音,所以我添加了一个名为 Speech 的功能,我认为它可以让它工作,但不是。
我将非常感谢任何给我一个关于如何将默认的美国男性口音更改为英式印度男性口音的好答案的人。
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 SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.onstart = function() {
console.log('voice is activated speak into the mic');
};
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']
.some(word => message.includes(word))) {
const finalText = hru[0];
speech.text = finalText;
} else if (['I/m doing bad', 'not good', 'I\'m not good', 'feeling sick', 'I\'m sick', 'feeling blue', 'feeling bad', 'I\'m upset', 'not good', 'I\'m angry']
.some(word => message.includes(word))) {
const finalText = hru[1];
speech.text = finalText;
}
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
}
function speak() {
responsiveVoice.speak(readOutLoud);
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button class="talk">Talk</button>
<h3 class="content"></h3>
<script src="https://code.responsivevoice.org/responsivevoice.js?key=RKLGFBGJ"></script>
</body>
</html>