Skip to content

Instantly share code, notes, and snippets.

@nosix
Created September 7, 2016 10:06
Show Gist options
  • Select an option

  • Save nosix/3de00175e75408ffcbe063e74f6e5ede to your computer and use it in GitHub Desktop.

Select an option

Save nosix/3de00175e75408ffcbe063e74f6e5ede to your computer and use it in GitHub Desktop.
Text to Speech using Watson
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text to Speech</title>
</head>
<body>
<div id="text-to-speech">
<input type="text" name="speech-text" placeholder="Sentence">
<button id="submit">Speech</button>
<audio id="speech"></audio>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#submit").click(function(){
var text = $("#text-to-speech input[name=speech-text]").val();
var url = "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=ja-JP_EmiVoice&accept=audio/wav&text=" + text;
$("#speech").attr("src", url)[0].play();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment