dimanche 26 novembre 2017

Google Chrome Text to Speech in Hindi

Am Developing a Application which speak user query results. i mean server return a text and user can listen that text too.

SO i used Chrome SpeechSynthesisUtterance utility. now the need come how speak that text in hindi. again i google and found some stuff. and now this utilty speaking only one figure in hindi. rest in English. text that am using is "your average value is, Net Revenue 20424987 ,values which are above average. shoes Net Revenue 102096080, clothing Net Revenue 49499808, and values which are below average, sports and fitness Net Revenue 4497, jewellery Net Revenue 61391, toys and games Net Revenue 427047,"

Please check below code and tell me how i can only make my code to speak numeric values in hindi

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://ift.tt/2apRjw3">
  <script src="http://ift.tt/2nYZfvi"></script>
  <script src="http://ift.tt/2aHTozy"></script>
<script>
var CHARACTER_LIMIT = 50;
var lang = "hi-IN";

var text = "your average value is, Net Revenue 20424987 ,values which are above average.  shoes Net Revenue 102096080, clothing Net Revenue 49499808, and values which are below average, sports and fitness Net Revenue 4497,  jewellery Net Revenue 61391,  toys and games Net Revenue 427047,";

speak(text, lang)

function speak(text, lang) {

  //Support for multipart text (there is a limit on characters)
  var multipartText = [];

  if (text.length > CHARACTER_LIMIT) {

    var tmptxt = text;

    while (tmptxt.length > CHARACTER_LIMIT) {

      //Split by common phrase delimiters
      var p = tmptxt.search(/[:!?;]+/);
      var part = '';

      //Coludn't split by priority characters, try commas
      if (p == -1 || p >= CHARACTER_LIMIT) {
        p = tmptxt.search(/[,]+/);
      }

      //Couldn't split by normal characters, then we use spaces
      if (p == -1 || p >= CHARACTER_LIMIT) {

        var words = tmptxt.split(' ');

        for (var i = 0; i < words.length; i++) {

          if (part.length + words[i].length + 1 > CHARACTER_LIMIT)
            break;

          part += (i != 0 ? ' ' : '') + words[i];

        }

      } else {

        part = tmptxt.substr(0, p + 1);

      }

      tmptxt = tmptxt.substr(part.length, tmptxt.length - part.length);

      multipartText.push(part);
      //console.log(part.length + " - " + part);

    }

    //Add the remaining text
    if (tmptxt.length > 0) {
      multipartText.push(tmptxt);
    }

  } else {

    //Small text
    multipartText.push(text);
  }


  //Play multipart text
  for (var i = 0; i < multipartText.length; i++) {

    //Use SpeechSynthesis
    //console.log(multipartText[i]);

    //Create msg object
    var msg = new SpeechSynthesisUtterance();
    //msg.voice = profile.systemvoice;
    //msg.voiceURI = profile.systemvoice.voiceURI;
    msg.volume = 1; // 0 to 1
    msg.rate = 1; // 0.1 to 10
    // msg.rate = usersetting || 1; // 0.1 to 10
    msg.pitch = 1; //0 to 2*/
    msg.text = multipartText[i];
    msg.speak = multipartText;
    msg.lang = lang;
    msg.onend = self.OnFinishedPlaying;
    msg.onerror = function (e) {
      console.log('Error');
      console.log(e);
    };
    /*GC*/
    msg.onstart = function (e) {
      var curenttxt = e.currentTarget.text;
      console.log(curenttxt);
      //highlight(e.currentTarget.text);
      //$('#showtxt').text(curenttxt);
      //console.log(e);
    };
    //console.log(msg);
    speechSynthesis.speak(msg);

  }

}
</script>
</head>
<body>

<div class="container">
  <h2>Animated Progress Bar</h2>
  <p>The .active class animates the progress bar:</p> 
  <div class="progress">
    <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width:10%">
      10%
    </div>
  </div>
</div>



Aucun commentaire:

Enregistrer un commentaire