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
parent 6f3a4ecd
<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>
// 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);
{
"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"]
}
]
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment