summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/examples/api/ttsEngine
diff options
context:
space:
mode:
authormitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-20 00:55:04 +0000
committermitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-20 00:55:04 +0000
commitb51f6ab136aa37f932c3d268693238f8f6b9e52f (patch)
tree3694b25628141493c63e58872841c852f49b6db7 /chrome/common/extensions/docs/examples/api/ttsEngine
parent6f3a4ecd452f649550c971fc612c3b0eff740d3f (diff)
downloadchromium_src-b51f6ab136aa37f932c3d268693238f8f6b9e52f.zip
chromium_src-b51f6ab136aa37f932c3d268693238f8f6b9e52f.tar.gz
chromium_src-b51f6ab136aa37f932c3d268693238f8f6b9e52f.tar.bz2
Sample extensions page does not feature chrome.ttsEngine.
Wrote a small sample TTS Engine that prints text to a small window on the bottom of the screen rather than synthesizing speech. BUG=117480 TEST=Manual Review URL: https://chromiumcodereview.appspot.com/9688004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/examples/api/ttsEngine')
-rw-r--r--chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine.zip0
-rw-r--r--chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.html49
-rw-r--r--chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.js115
-rw-r--r--chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/manifest.json17
4 files changed, 181 insertions, 0 deletions
diff --git a/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine.zip b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine.zip
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine.zip
diff --git a/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.html b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.html
new file mode 100644
index 0000000..62fd68d
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.html
@@ -0,0 +1,49 @@
+<html>
+<head>
+ <title>Console TTS Engine</title>
+ <style>
+ body {
+ font-family: arial, helvetica, sans-serif;
+ }
+ table {
+ text-align: center;
+ padding: 10px;
+ }
+ #text {
+ text-align: left;
+ padding: 4px;
+ border: 1px solid #aaa;
+ width: 99%;
+ min-height: 100px;
+ overflow: auto;
+ }
+ </style>
+ <script type="text/javascript">
+ function clearText() {
+ document.getElementById("text").innerHTML = "";
+ }
+ </script>
+</head>
+<body>
+ <table>
+ <tr>
+ <th>Voice Name</th>
+ <th>Language</th>
+ <th>Gender</th>
+ <th>Rate</th>
+ <th>Pitch</th>
+ <th>Volume</th>
+ </tr>
+ <tr>
+ <td id="voiceName"></td>
+ <td id="lang"></td>
+ <td id="gender"></td>
+ <td id="rate"></td>
+ <td id="pitch"></td>
+ <td id="volume"></td>
+ </tr>
+ </table>
+ <button onclick="clearText()">Clear</button>
+ <p id="text"></p>
+</body>
+</html>
diff --git a/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.js b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.js
new file mode 100644
index 0000000..3f69094f
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/console_tts_engine.js
@@ -0,0 +1,115 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var timeoutId;
+var ttsId = -1;
+var ttsWindow;
+var milliseconds;
+var curOptions;
+
+function areNewOptions(options) {
+ var properties = ['voiceName', 'lang', 'gender', 'rate', 'pitch', 'volume'];
+
+ for (var i = 0; i < properties.length; ++i) {
+ if (options[properties[i]] != curOptions[properties[i]]) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+function getTtsElement(element) {
+ return ttsWindow.document.getElementById(element);
+}
+
+function appendText(text) {
+ getTtsElement("text").innerHTML += text;
+}
+
+function logOptions() {
+ getTtsElement("voiceName").innerHTML = curOptions.voiceName;
+ getTtsElement("lang").innerHTML = curOptions.lang;
+ getTtsElement("gender").innerHTML = curOptions.gender;
+ getTtsElement("rate").innerHTML = curOptions.rate;
+ getTtsElement("pitch").innerHTML = curOptions.pitch;
+ getTtsElement("volume").innerHTML = curOptions.volume;
+}
+
+function logUtterance(utterance, index, sendTtsEvent) {
+ if (index == utterance.length) {
+ sendTtsEvent({'type': 'end', 'charIndex': utterance.length});
+ return;
+ }
+
+ appendText(utterance[index]);
+
+ if (utterance[index] == ' ') {
+ sendTtsEvent({'type': 'word', 'charIndex': index});
+ }
+ else if (utterance[index] == '.' ||
+ utterance[index] == '?' ||
+ utterance[index] == '!') {
+ sendTtsEvent({'type': 'sentence', 'charIndex': index});
+ }
+
+ timeoutId = setTimeout(function() {
+ logUtterance(utterance, ++index, sendTtsEvent)
+ }, milliseconds);
+}
+
+var speakListener = function(utterance, options, sendTtsEvent) {
+ clearTimeout(timeoutId);
+
+ sendTtsEvent({'type': 'start', 'charIndex': 0});
+
+ if (ttsId == -1) {
+ // Create a new window that overlaps the bottom 40% of the current window
+ chrome.windows.getCurrent(function(curWindow) {
+ chrome.windows.create(
+ {"url": "console_tts_engine.html",
+ "focused": false,
+ "top": Math.round(curWindow.top + 6/10 * curWindow.height),
+ "left": curWindow.left,
+ "width": curWindow.width,
+ "height": Math.round(4/10 * curWindow.height)},
+ function(newWindow) {
+ ttsId = newWindow.id;
+ ttsWindow = chrome.extension.getViews({"windowId": ttsId})[0];
+
+ curOptions = options;
+ logOptions();
+
+ // Fastest timeout == 1 ms (@ options.rate = 10.0)
+ milliseconds = 10 / curOptions.rate;
+ logUtterance(utterance, 0, sendTtsEvent);
+ }
+ );
+ });
+ } else {
+ if (areNewOptions(options)) {
+ curOptions = options;
+ logOptions();
+
+ milliseconds = 10 / curOptions.rate;
+ }
+
+ logUtterance(utterance, 0, sendTtsEvent);
+ }
+
+};
+
+var stopListener = function() {
+ clearTimeout(timeoutId);
+};
+
+var removedListener = function(windowId, removeInfo) {
+ if (ttsId == windowId) {
+ ttsId = -1;
+ }
+}
+
+chrome.ttsEngine.onSpeak.addListener(speakListener);
+chrome.ttsEngine.onStop.addListener(stopListener);
+chrome.windows.onRemoved.addListener(removedListener);
diff --git a/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/manifest.json b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/manifest.json
new file mode 100644
index 0000000..43e7edc
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/ttsEngine/console_tts_engine/manifest.json
@@ -0,0 +1,17 @@
+{
+ "name": "Console TTS Engine",
+ "version": "2.0",
+ "description": "A \"silent\" TTS engine that prints text to a small window rather than synthesizing speech.",
+ "permissions": ["ttsEngine", "tabs"],
+ "background": {
+ "scripts": ["console_tts_engine.js"]
+ },
+ "tts_engine": {
+ "voices": [
+ {
+ "voice_name": "Console",
+ "event_types": ["start", "word", "sentence", "end"]
+ }
+ ]
+ }
+}