From 27509f29c0123a7ce137233f9b21b1a860c7937c Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Tue, 14 Jul 2009 02:25:24 +0000 Subject: Create voices combobox widget; make Speak library deploying friendly --- diff --git a/Speak.activity/__init__.py b/Speak.activity/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Speak.activity/__init__.py diff --git a/Speak.activity/activity.py b/Speak.activity/activity.py index 886b4a2..f4b324f 100644 --- a/Speak.activity/activity.py +++ b/Speak.activity/activity.py @@ -45,6 +45,7 @@ import face import brain import chat import espeak +import widgets from messenger import Messenger, SERVICE logger = logging.getLogger('speak') @@ -59,9 +60,6 @@ class SpeakActivity(SharedActivity): SharedActivity.__init__(self, self.notebook, SERVICE, handle) bounds = self.get_allocation() - # pick a voice that espeak supports - self.voices = voice.allVoices() - # make an audio device for playing back and rendering audio self.connect( "notify::active", self._activeCb ) @@ -228,20 +226,15 @@ class SpeakActivity(SharedActivity): def make_voice_bar(self): voicebar = gtk.Toolbar() - + # button = ToolButton('change-voice') # button.set_tooltip("Change Voice") # button.connect('clicked', self.change_voice_cb) # voicebar.insert(button, -1) # button.show() - - self.voice_combo = ComboBox() - voicenames = self.voices.keys() - voicenames.sort() - for name in voicenames: - self.voice_combo.append_item(self.voices[name], name) - self.voice_combo.set_active(voicenames.index( - self.face.status.voice.friendlyname)) + + self.voice_combo = widgets.Voices() + self.voice_combo.select(self.face.status.voice.friendlyname) combotool = ToolComboBox(self.voice_combo) voicebar.insert(combotool, -1) combotool.show() diff --git a/Speak.activity/brain.py b/Speak.activity/brain.py index c9ef2b4..e39e91e 100644 --- a/Speak.activity/brain.py +++ b/Speak.activity/brain.py @@ -39,7 +39,7 @@ BOTS = { 'predicates': { 'name': 'Alice', 'master': 'the Sugar Community' } } } -DEFAULT = voice.DEFAULT +DEFAULT = voice.defaultVoice() if not BOTS.has_key(DEFAULT): DEFAULT = voice.allVoices()[_('English')] diff --git a/Speak.activity/espeak.py b/Speak.activity/espeak.py index c57aa2a..4076e3b 100644 --- a/Speak.activity/espeak.py +++ b/Speak.activity/espeak.py @@ -12,8 +12,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import pygst -pygst.require("0.10") import gst import gobject import subprocess diff --git a/Speak.activity/espeak_gst.py b/Speak.activity/espeak_gst.py index 1c9c738..f12453d 100644 --- a/Speak.activity/espeak_gst.py +++ b/Speak.activity/espeak_gst.py @@ -15,8 +15,6 @@ import logging logger = logging.getLogger('speak') -import pygst -pygst.require("0.10") import gst import espeak diff --git a/Speak.activity/face.py b/Speak.activity/face.py index ab63412..5ad632c 100644 --- a/Speak.activity/face.py +++ b/Speak.activity/face.py @@ -43,7 +43,7 @@ FACE_PAD = 2 class Status: def __init__(self): - self.voice = voice.DEFAULT + self.voice = voice.defaultVoice() self.pitch = espeak.PITCH_DEFAULT self.rate = espeak.RATE_DEFAULT self.eyes = [eye.Eye] * 2 @@ -171,10 +171,10 @@ class View(gtk.EventBox): def say(self, something): self._audio.speak(self._peding or self.status, something) - + def say_notification(self, something): status = (self._peding or self.status).clone() - status.voice = voice.DEFAULT + status.voice = voice.defaultVoice() self._audio.speak(status, something) def shut_up(self): diff --git a/Speak.activity/voice.py b/Speak.activity/voice.py index fd58b5e..6cc6f9c 100644 --- a/Speak.activity/voice.py +++ b/Speak.activity/voice.py @@ -69,7 +69,7 @@ expectedVoiceNames = [ ] _allVoices = {} -DEFAULT = None +_defaultVoice = None class Voice: def __init__(self, language, name): @@ -94,10 +94,15 @@ def allVoices(): return _allVoices -def _defaultVoice(): +def defaultVoice(): """Try to figure out the default voice, from the current locale ($LANG). Fall back to espeak's voice called Default.""" + global _defaultVoice + + if _defaultVoice: + return _defaultVoice + voices = allVoices() def fit(a,b): @@ -122,6 +127,5 @@ def _defaultVoice(): best = voice print "Best voice for LANG %s seems to be %s %s" % (lang, best.language, best.friendlyname) + _defaultVoice = best return best - -DEFAULT = _defaultVoice() diff --git a/Speak.activity/widgets.py b/Speak.activity/widgets.py new file mode 100644 index 0000000..9324ca3 --- /dev/null +++ b/Speak.activity/widgets.py @@ -0,0 +1,30 @@ +# 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 + +from port.widgets import ComboBox + +import voice + +class Voices(ComboBox): + def __init__(self, **kwargs): + ComboBox.__init__(self, **kwargs) + + voices = voice.allVoices() + voicenames = voices.keys() + voicenames.sort() + + for name in voicenames: + self.append_item(voices[name], name) + + self.select(voice.defaultVoice()) -- cgit v0.9.1