Created
April 2, 2013 07:41
-
-
Save josher19/5290576 to your computer and use it in GitHub Desktop.
mSpeak -- Speak using Microsoft Speak API and Google speech input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
</head> | |
<body> | |
<h1><a href="https://api.microsofttranslator.com/V2/http.svc/Speak?appId=TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV&text=Welcome+to+the+Audio+Site&language=en&format=audio%2fwav" target=_blank>Welcome to the Audio Site</a></h1> | |
<form method=get action="https://api.microsofttranslator.com/V2/http.svc/Speak" id="speakForm"> | |
<label>App ID: <input name=appId disabled=true value="TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV" /></label> <br/> | |
<label>Text: <input type=text name=text value="油猴汽车快修" speech x-webkit-speech /></label> <br/> | |
<!-- <input name=language value=en /> <br/> --> | |
<label>Language: <select name=language> | |
<option value="en">英语 English</option> | |
<option value="zh-CNS" selected>汉语 Chinese (Simplified)</option> | |
<option value="zh-CHT">Chinese (Traditional)</option> | |
<option value="nl">Dutch</option> | |
<option value="fr">French</option> | |
<option value="de">German</option> | |
<option value="it">Italian</option> | |
<option value="ko">Korean</option> | |
<option value="no">Norwegian</option> | |
<option value="pt">Portuguese</option> | |
<option value="ru">Russian</option> | |
<option value="es">Spanish</option> | |
<option value="sv">Swedish</option> | |
</select></label> <br /> | |
<label>Audio Format: <input type=text name=format value="audio/wav" /></label> <br/> | |
<input type=submit id="sayIt" value="Say It" /> | |
</form> | |
<audio controls id="audio" preload="none"> | |
<source src="https://api.microsofttranslator.com/V2/http.svc/Speak?appId=TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV&text=%E6%B2%B9%E7%8C%B4%E6%B1%BD%E8%BD%A6%E5%BF%AB%E4%BF%AE&language=zh-CN&format=audio%2Fwav" type="audio/wav" preload="none"> | |
<source xsrc="https://api.microsofttranslator.com/V2/http.svc/Speak?appId=TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV&text=%E6%B2%B9%E7%8C%B4%E6%B1%BD%E8%BD%A6%E5%BF%AB%E4%BF%AE&language=zh-CN&format=audio%2Fmp3" type="audio/mpeg" preload="none"> | |
Sorry, your browser does not support the audio tag. | |
</audio> | |
<div id="errors"></div> | |
<script type="text/javascript"> | |
if (typeof encodeURIComponent != "function") encodeURIComponent = function(x) { return x }; | |
var speakForm = document.getElementById("speakForm"); | |
speakForm.text.onkeyup = function(ev) { this.size = 3 + this.value.length } | |
function undisable() { | |
// document.getElementById('errors').innerHTML = ""; | |
// document.getElementById('sayIt').disabled = false; | |
} | |
function showerror(ev) { | |
undisable(); | |
document.getElementById('errors').innerHTML = "Got: " + (ev.type || ev.stack); | |
} | |
var audio = document.getElementById('audio'); | |
if (audio && audio.addEventListener) { | |
// audio.removeEventListener("canplaythrough", undisable, false); | |
audio.addEventListener("canplaythrough", undisable, false); | |
// audio.removeEventListener("error", showerror, false); | |
// audio.addEventListener("error", showerror, false); | |
// audio.addEventListener("abort", showerror, false); | |
} | |
speakForm.onsubmit = function(ev) { | |
var action = speakForm.action + "?" | |
var els = speakForm.elements, el = els[els.length-1]; | |
// for(var i=0; i<els.length; ++i) { var el = els[i]; console.log(el.name,escape(el.value)) } | |
for(var i=0; i<els.length; ++i) { | |
el = els[i]; | |
if (el.name) action += "&" + el.name + "=" + encodeURIComponent(el.value) | |
} | |
var format = speakForm.format.value | |
// alert(action); | |
if (typeof console == "object") console.log(action); | |
var source = audio.querySelector ? audio.querySelector('source') : audio.children[0] ; | |
if (format) source.type = format; | |
if (action) source.src = action; | |
var submit = document.getElementById('sayIt'); | |
if (submit) { | |
document.oncontextmenu = undisable; | |
// submit.disabled = true; | |
} | |
/* | |
var parent = audio.parentNode || document.body; | |
parent.removeChild(audio); | |
parent.appendChild(audio); | |
*/ | |
audio.load() | |
audio.play(); | |
return false; | |
} | |
</script> | |
<hr noshade /> | |
<div id="description" class="info"> | |
<p> | |
If you use the Google Chrome Browser, | |
you can click the "Microphone" icon to speak and have Google convert your voice to text | |
<i>(sorry, does not work for Chinese)</i>. Click the "<a href="#sayIt" onclick="alert(this.parentNode.textContent)">Say It</a>" button to say the text. Click the "<a href="#audio" onclick="audio.play()">play</a>" icon to say it again. | |
</p> | |
<p> | |
Will not work on old versions of Internet Explorer — Sorry, your browser does not support the audio tag. | |
</p> | |
</div> | |
<hr noshade /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment