Gozala (owner)

Forks

  • gist: 181634 by debz Converts IPA code to speech created Sat Sep 05 21:06:41 -0700 2009

Revisions

gist: 41328 Download_button fork
public
Description:
Ubiquity Command - Say
Public Clone URL: git://gist.github.com/41328.git
Embed All Files: show embed
Say.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Say
var URL = null;
CmdUtils.CreateCommand({
    name: "say",
    //icon: "http://",
    description: "Pronounces the selected/specified text",
    author: { name: "Irakli Gozalishvili", email: "rfobic@gmail.com"},
    homepage: 'http://rfobic.blogspot.com/2008/10/ubiquity-command-say.html',
    help: 'Select or type the text to pronounce it',
    takes: {"sentence": noun_arb_text},
    
    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="100%" 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,300})(?=\s|$)/gm);
        this.frame.addEventListener('load',function() {
            if (self.frame.contentDocument.location != 'about:blank') {
                var player = jQuery(self.frame.contentDocument).find('video')[0];
                player.addEventListener('ended', function() {
                    self.playNextPart.call(self);
                }, true);
            }
        }, true);
 
        this.playNextPart();
    },
 
    execute: function(noun) {
        window.getBrowser().selectedTab = window.getBrowser().addTab(URL);
    },
    
    // Core
    pblock : null,
    
    voice : 'crystal',
    
    serviceURL : 'http://192.20.225.55/tts/cgi-bin/nph-talk',
    
    text : [],
    
    url : '',
    
    frame : null,
    
    messageBar : null,
    
    textBar : null,
    
    loader : null,
    
    textToUrl: function(text) {
        return jQuery.ajax({
                    url : this.serviceURL,
                    type: "POST",
                    async : false,
                    data : {
                        voice : this.voice,
                        txt : text,
                    }
        }).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('Pronouncing text:');
        } else {
            this.messageBar.text('Finished pronouncing the text');
            this.textBar.text('');
        }
    }
});