Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Sound.py
blob: 546c5b25e954c33fde2a28d054cbfe7baaca3135 (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os

import gi
from gi.repository import GObject

from JAMediaReproductor import JAMediaReproductor
from MplayerReproductor import MplayerReproductor

PITCH_MAX = 200
RATE_MAX = 200
wavpath = "/tmp/speak.wav"

def make_file(pitch, rate, voice, text):
    """Genera el archivo de audio."""

    rate = 60 + int(((175 - 80) * 2) * rate / RATE_MAX)
    command = "espeak -w %s -p %s -s %s -v%s \"%s\"" % (wavpath,
        str(pitch), str(rate), voice, text)
    ret = os.system(command)
    file = open(wavpath, "r")
    file.flush()
    #print file.readlines()
    os.fsync(file)
    file.close()
    return ret

class Sound(GObject.GObject):
    """Interactua entre espeak y JAMediaReproductor."""
    
    def __init__(self, xid):
        
        GObject.GObject.__init__(self)
        
        self.pitch = 0
        self.rate = 0
        self.voice = "es"
        self.text = ""
        self.estado = None
        
        self.player = MplayerReproductor(xid) #JAMediaReproductor(xid)
        
    def set_voice(self, value):
        """Cuando cambia el lenguaje."""
        
        self.voice = value
    
    def set_pitch(self, value):
        """Cuando cambia pitch."""
        
        self.pitch = value
        
    def set_rate(self, value):
        """Cuando cambia rate."""
        
        self.rate = value
        
    def speak(self, text):
        """Cuando habla."""
        
        self.text = text
        
        if not make_file(self.pitch, self.rate, self.voice, self.text):
            self.player.load(wavpath)