0

I've asked this question a lot and haven't gotten a good answer, so please help me.

I'm currently working on a chatbot which works perfectly fine, the only thing that is wrong with it is that I want to change the accent to an Indian Male one, but the default is US Male.

I tried using HTML lang = 'en-IN' (it was in tags when inserted), but that didn't work so I tried putting recognition.lang = 'en-IN' after const recognition, but that didn't work either. My final try was using responisvevoice.org, that was easy. I just copied the link they had given me and pasted it but that also didn't work! I was sure that just pasting the link they had given me wouldn't magically change the accent of my chatbot, so I added a function called speech which I thought would make it work but nope.

I would be very grateful to anyone who gives me a good answer on how to change the default US Male accent to an Engish Indian Male accent.

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>
Azametzin
  • 5,223
  • 12
  • 28
  • 46
Love2Code
  • 440
  • 6
  • 19
  • 1
    Have you added a script tag for your own javascript file? – Frazer Jun 27 '19 at 10:02
  • Also, I think the US/IN English issue may be the same as my US/GB English issue [here](https://stackoverflow.com/questions/52975068/speechsynthesis-in-android-chrome-cannot-change-english-voice-from-us-english). – Frazer Jun 27 '19 at 10:06
  • @Frazer The script tag is inside the body. And yes it looks like we're having the same issue here. – Love2Code Jun 27 '19 at 15:38
  • @Frazer Just an update but now I have tried absolutely everything possible and this thing still isn't working. I've tried recognition.lang and .voice and I've tried using en_IN instead of en-IN. I've also tried using double quotes instead of single quotes. If you can please give me some advice I've been trying to answer this question for weeks. – Love2Code Jun 27 '19 at 18:58
  • 1
    The script tag in the body is for responsive voice. You need a second tag for the javascript file that you have written. Also your js file contains speech synthesis (i.e. the computer talking what is written) and speech recognition (i.e. the computer writing what it hears). Which are you after? – Frazer Jun 28 '19 at 09:53
  • So are you saying I should use external JS to fix it? I need speech synthesis to be in a different accent. – Love2Code Jun 28 '19 at 14:04

0 Answers0