| OLD | NEW |
| 1 <html> | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 <script> | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 3 function setStartIcon() { | 5 function setStartIcon() { |
| 4 chrome.browserAction.setIcon({ path: "start.png" }); | 6 chrome.browserAction.setIcon({ path: "start.png" }); |
| 5 } | 7 } |
| 6 | 8 |
| 7 function setStopIcon() { | 9 function setStopIcon() { |
| 8 chrome.browserAction.setIcon({ path: "stop.png" }); | 10 chrome.browserAction.setIcon({ path: "stop.png" }); |
| 9 } | 11 } |
| 10 | 12 |
| 11 chrome.browserAction.onClicked.addListener(function(tab) { | 13 chrome.browserAction.onClicked.addListener(function(tab) { |
| 12 chrome.experimental.speechInput.isRecording(function(recording) { | 14 chrome.experimental.speechInput.isRecording(function(recording) { |
| 13 if (!recording) { | 15 if (!recording) { |
| 14 chrome.experimental.speechInput.start({}, function() { | 16 chrome.experimental.speechInput.start({}, function() { |
| 15 if (chrome.extension.lastError) { | 17 if (chrome.extension.lastError) { |
| 16 alert("Couldn't start speech input: " + chrome.extension.lastError.mes
sage); | 18 alert("Couldn't start speech input: " + |
| 19 chrome.extension.lastError.message); |
| 17 setStartIcon(); | 20 setStartIcon(); |
| 18 } else { | 21 } else { |
| 19 setStopIcon(); | 22 setStopIcon(); |
| 20 } | 23 } |
| 21 }); | 24 }); |
| 22 } else { | 25 } else { |
| 23 chrome.experimental.speechInput.stop(function() { | 26 chrome.experimental.speechInput.stop(function() { |
| 24 setStartIcon(); | 27 setStartIcon(); |
| 25 }); | 28 }); |
| 26 } | 29 } |
| 27 }); | 30 }); |
| 28 }); | 31 }); |
| 29 | 32 |
| 30 chrome.experimental.speechInput.onError.addListener(function(error) { | 33 chrome.experimental.speechInput.onError.addListener(function(error) { |
| 31 alert("Speech input failed: " + error.code); | 34 alert("Speech input failed: " + error.code); |
| 32 setStartIcon(); | 35 setStartIcon(); |
| 33 }); | 36 }); |
| 34 | 37 |
| 35 chrome.experimental.speechInput.onResult.addListener(function(result) { | 38 chrome.experimental.speechInput.onResult.addListener(function(result) { |
| 36 alert(result.hypotheses[0].utterance); | 39 alert(result.hypotheses[0].utterance); |
| 37 setStartIcon(); | 40 setStartIcon(); |
| 38 }); | 41 }); |
| 39 </script> | |
| 40 </html> | |
| OLD | NEW |