Instantly share code, notes, and snippets.

@eversonl /x
Created Feb 15, 2009

Embed
What would you like to do?
vozme
// vozme
var URL = null;
CmdUtils.CreateCommand({
name: ["vozme"],
icon: "http://vozme.com/favicon.ico",
description: "Pronounces the selected/specified text",
author: { name: "Lee Everson", email: "lee@0-21.co.uk"},
homepage: 'http://www.0-21.co.uk/index.php/200902173422/Blog/Lee-s-Blog/My-Ubiquity-commands.html',
help: 'Select or type the text to speak it',
arguments: [{
role: "object",
nountype: noun_arb_text,
label: "sentence"
}],
preview: function(pblock, noun) {
var self = this;
this.pblock = jQuery(pblock);
pblock.innerHTML = CmdUtils.renderTemplate(
'\n<div>\n\t<img id="loader" src="chrome://global/skin/icons/loading_16.png" alt=""/>' +
'\n\t<strong id="message-bar"></strong>\n</div>' +
'\n<div id="text-bar" style="font-size: 11px;"></div>\n' +
'\n<iframe style="visibility: hidden" id="player" width="100%" height="20%" src="about:blank" >' +
'\n</iframe>',
{
text : this.text[1],
}
);
this.frame = this.pblock.find("iframe")[0];
this.loader = this.pblock.find("#loader")[0];
this.messageBar = this.pblock.find("#message-bar");
this.textBar = this.pblock.find("#text-bar");
this.text = noun.text.split(/([\s\S]{1,9900})(?=\s|$)/gm);
this.frame.addEventListener('load',function() {
if (self.frame.contentDocument.location != 'about:blank') {
var player = jQuery(self.frame.contentDocument).find('object')[0];
player.addEventListener('end', function() {
self.playNextPart.call(self);
}, true);
}
}, true);
this.playNextPart();
},
execute: function(noun) {
// window.getBrowser().selectedTab = window.getBrowser().addTab(URL);
},
// Core
pblock : null,
serviceURL : 'http://vozme.com/text2voice.php?',
gn : 'ml',
lang : 'en',
// tgt : 'voice_'+parseInt(Math.random()*100000),
full : 'full',
text : [],
url : '',
frame : null,
messageBar : null,
textBar : null,
loader : null,
textToUrl: function(text) {
return jQuery.ajax({
url : this.serviceURL + 'lang=' + this.lang + '&gn=' + this.gn + '&text=' + this.text[0] + '&interface=' + this.full,
// type: "POST",
// async : false,
// data : {
// text : this.text[0],
// lang : this.lang,
// gn : this.gn,
//interface : this.full,
// }
}).channel.URI.spec;
},
playNextPart : function() {
this.text.shift();
while (this.text[0] == '')
this.text.shift();
if (this.text.length > 0) {
this.loader.style.visibility = 'visible';
this.messageBar.text('Converting text to speech:');
this.textBar.text(this.text[0]);
this.url = this.textToUrl(this.text[0]);
this.frame.src = this.url;
this.loader.style.visibility = 'hidden';
this.messageBar.text('Reading text:');
} else {
this.messageBar.text('Finished reading the text');
this.textBar.text('');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment