Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Speak.py
blob: 9a0a5a28c2771e8eb038ff2a8f4db7c965bc0e34 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/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 sys
import os

import gi
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
from gi.repository import GdkX11

from Widgets import Speaking
from Widgets import Toolbar
from Widgets import ToolbarPitchRate
from Widgets import ToolbarFace
from Sound import Sound

BASE = os.path.dirname(__file__)

GObject.threads_init()
Gdk.threads_init()

class Speak(Gtk.Window):
    
    def __init__(self):
        Gtk.Window.__init__(self)
        
        self.set_title("Hablar con Sara")
        self.set_icon_from_file(os.path.join(BASE, "icons", "face.svg"))
        self.set_resizable(True)
        self.set_border_width(0)
        self.set_size_request(640, 480)
        self.modify_bg(0, Gdk.Color(65000, 28260, 30516))
        
        self.add_events(
            Gdk.EventMask.POINTER_MOTION_HINT_MASK |
            Gdk.EventMask.POINTER_MOTION_MASK)
        
        self.toolbar = None
        self.toolbarpitchrate = None
        self.toolbarface = None
        self.notebook = None
        self.speaking = None
        self.sound = None
        
        self.dinamic_toolbars = []
        
        self.setup_init()
        
    def setup_init(self):
        """Se crean los objetos y se empaqueta todo."""
        
        self.toolbar = Toolbar()
        self.toolbarpitchrate = ToolbarPitchRate()
        self.toolbarface = ToolbarFace()
        self.notebook = Gtk.Notebook()
        self.notebook.set_show_border(False)
        self.notebook.set_show_tabs(False)
        
        vbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
        vbox.pack_start(self.toolbar, False, False,0)
        vbox.pack_start(self.toolbarpitchrate, False, False,0)
        vbox.pack_start(self.toolbarface, False, False,0)
        
        self.speaking = Speaking() # Pagina inicial en el notebook
        self.notebook.append_page(self.speaking, Gtk.Label(""))
        vbox.pack_start(self.notebook, True, True,0)
        
        self.dinamic_toolbars = [self.toolbarpitchrate, self.toolbarface]
        
        self.add(vbox)
        
        self.show_all()
        
        map(self.hide_widgets, self.dinamic_toolbars)
        
        xid = self.speaking.face.get_property('window').get_xid()
        self.sound = Sound(xid)
        
        self.sound.set_pitch(100)
        self.sound.set_rate(100)
        self.sound.set_voice('es')
        
        self.connect("motion_notify_event", self.mouse_moved)
        
        self.toolbar.connect("switch-voice", self.switch_voice)
        #self.toolbar.connect("switch-desktop", # cambiar entre speaking, chat y robot)
        self.toolbar.connect("switch-toolbar", self.switch_toolbar)
        
        self.toolbarpitchrate.connect("pitch", self.switch_pitch)
        self.toolbarpitchrate.connect("rate", self.switch_rate)
        
        self.toolbarface.connect("number-eyes", self.number_eyes)
        self.toolbarface.connect("switch-type-mouth", self.switch_type_mouth)
        self.toolbarface.connect("switch-type-eyes", self.switch_type_eyes)
        
        self.speaking.connect("speak", self.speak)
        
        self.connect("delete_event", self.delete_event)
        self.connect("destroy", self.salir)
        
    def speak(self, widget, value):
        """Cuando el usuario ingresa texto para hablar."""

        self.sound.speak(value)
        
    def switch_pitch(self, widget, value):
        """cuando cambia pitch."""
        
        self.sound.set_pitch(value)
        self.sound.speak("Campo Modificado.")
        
    def switch_rate(self, widget, value):
        """Cuando cambia rate."""
        
        self.sound.set_rate(value)
        self.sound.speak("Velocidad Modificada.")
        
    def number_eyes(self, widget, value):
        """Recibe la cantidad de ojos que deben dibujarse."""
        
        self.speaking.face.set_number_eyes(value)
        self.sound.speak("Ojos Modificados.")
        
    def switch_type_mouth(self, widget, value):
        """Recibe el tipo de dibujo para la boca."""
        
        self.speaking.face.set_type_mouth(value)
        self.sound.speak("Boca Modificada.")
        
    def switch_type_eyes(self, widget, value):
        """Recibe el tipo de ojos a dibujar."""
        
        self.speaking.face.set_type_eyes(value)
        self.sound.speak("Ojos Modificados.")
    
    def switch_toolbar(self, widget, value):
        """Para que se muestre la toolbar pitch-rate o face"""
        
        if value == "pitch-rate":
            if self.toolbarpitchrate.get_visible():
                self.toolbarpitchrate.hide()
            else:
                map(self.hide_widgets, self.dinamic_toolbars)
                self.toolbarpitchrate.show()
                
        elif value == "face":
            if self.toolbarface.get_visible():
                self.toolbarface.hide()
            else:
                map(self.hide_widgets, self.dinamic_toolbars)
                self.toolbarface.show()
    
    def hide_widgets(self, objeto):
        """Esta funcion es llamada desde self.switch_toolbar()"""
        
        if objeto.get_visible(): objeto.hide()
        
    def switch_voice(self, widget, value):
        """Cuando cambia el lenguaje."""
        
        self.sound.set_voice(value)
        self.sound.speak("Voz Modificada.")
        
    def delete_event(self, widget = None, event = None, data = None):
        self.salir()
        return False
    
    def salir(self, widget = None, senial = None):
        sys.exit(0)
        
    def mouse_moved(self, widget, event):
        """Le dice a la cara hacia donde mirar."""
        
        pos = (event.x, event.y)
        self.speaking.look_at(pos)
        
if __name__=="__main__":
    Speak()
    Gtk.main()