Created
January 21, 2015 12:50
-
-
Save obligingxx/f894d564035244fbc94b to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<head> | |
<script type="text/javascript"> | |
var 動物名 ; | |
var 訊息; | |
var 最終辨識; | |
var 中間辨識訊息; | |
var 辨識或停止; | |
var 最終辨識訊息變數 = ''; | |
var 辨識中 = false; | |
function startButton(event) | |
{ | |
訊息 = document.getElementById("訊息"); | |
最終辨識 = document.getElementById("最終辨識"); | |
中間辨識訊息 = document.getElementById("中間辨識訊息"); | |
辨識或停止 = document.getElementById("辨識或停止"); | |
辨識語言 = document.getElementById("辨識語言"); | |
if (辨識中) | |
{ | |
語音辨識物件.stop(); | |
} | |
else | |
{ | |
最終辨識.value = ''; | |
中間辨識訊息.value = ''; | |
最終辨識訊息變數 = ''; | |
語音辨識物件.lang = "en-US"; | |
語音辨識物件.start(); | |
} | |
} | |
if (!('webkitSpeechRecognition' in window)) | |
{ | |
訊息.innerText = "本瀏覽器不支援語音辨識,請更換瀏覽器!(Chrome 25 版以上才支援語音辨識)"; | |
} | |
else | |
{ | |
var 語音辨識物件 = new webkitSpeechRecognition(); | |
語音辨識物件.continuous = true; | |
語音辨識物件.interimResults = true; | |
語音辨識物件.onstart = function() | |
{ | |
辨識中 = true; | |
辨識或停止.value = "Stop"; | |
}; | |
語音辨識物件.onend = function() | |
{ | |
辨識中 = false; | |
辨識或停止.value = "Start"; | |
訊息.innerText = ""; | |
}; | |
語音辨識物件.onresult = function(event) | |
{ | |
var 中間結果 = ''; | |
for (var i = event.resultIndex; i < event.results.length; ++i) | |
{ | |
if (event.results[i].isFinal) | |
{ | |
最終辨識訊息變數 = event.results[i][0].transcript; | |
} | |
else | |
{ | |
中間結果 = event.results[i][0].transcript; | |
} | |
} | |
if (最終辨識訊息變數.trim().length > 0) | |
{ | |
最終辨識.value = 最終辨識訊息變數; | |
if(最終辨識.value == 動物名 || 最終辨識訊息變數 == ' '+動物名) | |
{ | |
alert("yes"); | |
selecttool(); | |
} | |
} | |
if (中間結果.trim().length > 0) | |
中間辨識訊息.value = 中間結果; | |
}; | |
} | |
</script> | |
<script language="javascript"> | |
a = 4 | |
var 產生隨機數字 = Math.random(); | |
var 四捨五入隨機數字 = Math.round(產生隨機數字 * (a-1))+1; | |
function 動物屬性初始宣告() | |
{ | |
this.src = '' | |
this.border = '' | |
this.alt = '' | |
this.sound = '' | |
} | |
b = new Array() | |
for(var i=1; i<=a; i++) { b[i] = new 動物屬性初始宣告() } | |
b[1].src = "https://dl.dropboxusercontent.com/u/56365948/bird.jpg" | |
b[1].border = "0" | |
b[1].alt = "bird" | |
b[1].sound = "https://dl.dropboxusercontent.com/u/56365948/Birds.wav" | |
b[2].src = "https://dl.dropboxusercontent.com/u/56365948/elephant.jpg" | |
b[2].border = "0" | |
b[2].alt = "elephant" | |
b[2].sound = "https://dl.dropboxusercontent.com/u/56365948/elephant.wav" | |
b[3].src = "https://dl.dropboxusercontent.com/u/56365948/dog.jpg" | |
b[3].border = "0" | |
b[3].alt = "dog" | |
b[3].sound = "https://dl.dropboxusercontent.com/u/56365948/Dog.wav" | |
b[4].src = "https://dl.dropboxusercontent.com/u/56365948/monkey.jpg" | |
b[4].border = "0" | |
b[4].alt = "monkey" | |
b[4].sound = "https://dl.dropboxusercontent.com/u/56365948/monkey2.wav" | |
var visa = ""; | |
動物名=b[四捨五入隨機數字].alt; | |
alert(動物名);//test | |
</script> | |
Final Result:<input id="最終辨識" type="text" size="60" value=""/><BR/> | |
Interim Result:<input id="中間辨識訊息" type="text" size="60" value=""/><BR/> | |
<input id="辨識或停止" type="button" value="Start" onclick="startButton(event)"/><BR/> | |
<label id="訊息"></label> | |
</head> | |
<body> | |
<input type="button" value="voice" onClick="voice()"/> | |
<script language="javascript"> | |
function voice() | |
{ | |
document.getElementById("voi").innerHTML = "<embed src= '"+b[四捨五入隨機數字].sound+"'width=0 height=0>"; | |
} | |
function selecttool() | |
{ | |
document.getElementById("my_div").innerHTML = "<img src='"+b[四捨五入隨機數字].src+"' width=200 height=200>"; | |
} | |
</script> | |
<div id="my_div" ></div> | |
<div id="voi" ></div> | |
</body> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment