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