Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Sound.py
diff options
context:
space:
mode:
Diffstat (limited to 'Sound.py')
-rw-r--r--Sound.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/Sound.py b/Sound.py
new file mode 100644
index 0000000..546c5b2
--- /dev/null
+++ b/Sound.py
@@ -0,0 +1,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)
+ \ No newline at end of file