Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
muflone committed Jun 20, 2009
1 parent 48ed995 commit 586d98d
Show file tree
Hide file tree
Showing 11 changed files with 1,179 additions and 0 deletions.
70 changes: 70 additions & 0 deletions EspeakFrontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
##
# Project: gespeaker - A GTK frontend for espeak
# Author: Muflone Ubuntu Trucchi <[email protected]>
##

import SubprocessWrapper

class EspeakFrontend(object):
def __init__(self):
self.procTalk = None
print 'python version detected: %d.%d' % (
SubprocessWrapper.PYTHON_VERSION[0], SubprocessWrapper.PYTHON_VERSION[1])

def isPlaying(self):
"Check if a process is still running"
return self.procTalk and (
self.procTalk[0].poll() == None or self.procTalk[1].poll() == None)

def pauseOrResume(self, status):
"Pause or Resume the playing, based on status"
if self.procTalk:
# Check if espeak is still runnning
if self.procTalk[0].poll() == None:
if status:
self.procTalk[0].stop()
else:
self.procTalk[0].resume()
# Check if player is still runnning
if self.procTalk[1].poll() == None:
if status:
self.procTalk[1].stop()
else:
self.procTalk[1].resume()

def play(self, cmdEspeak, cmdPlayer):
"Play the command provided"
# Execute espeak and pipe it with player
procEspeak = SubprocessWrapper.Popen(cmdEspeak.split(),
stdout=SubprocessWrapper.PIPE)
procPlay = SubprocessWrapper.Popen(cmdPlayer.split(),
stdin=procEspeak.stdout,
stdout=SubprocessWrapper.PIPE,
stderr=SubprocessWrapper.PIPE)
# Save both processes espeak and player
self.procTalk = (procEspeak, procPlay)

def stop(self):
"Stop audio killing espeak and player"
# If played at least once then we have procTalk
if self.procTalk:
# Check if espeak is still running
if self.procTalk[0].poll() == None:
print 'killing espeak with pid %d' % self.procTalk[0].pid
self.procTalk[0].terminate()
# Check if player is still runnning
if self.procTalk[1].poll() == None:
print 'killing player with pid %d' % self.procTalk[1].pid
self.procTalk[1].terminate()
# We don't need processes anymore
self.procTalk = None
return True
else:
return False

def loadLanguages(self, cmdEspeak):
"Load languages list from espeak"
print 'loading languages from %s --voices' % cmdEspeak
proc = SubprocessWrapper.Popen((cmdEspeak, '--voices'),
stdout=SubprocessWrapper.PIPE)
return proc.communicate()[0].split('\n')[1:-1]
51 changes: 51 additions & 0 deletions SubprocessWrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
##
# Project: gespeaker - A GTK frontend for espeak
# Author: Muflone Ubuntu Trucchi <[email protected]>
##

import subprocess
import sys
import os

PIPE = subprocess.PIPE
PYTHON_VERSION = sys.version_info[0:2]

class Popen(object):
def __init__(self, args, stdin=None, stdout=None, stderr=None, shell=False):
self.process = subprocess.Popen(args=args,
stdin=stdin, stdout=stdout, stderr=stderr, shell=shell)
self.stdin = self.process.stdin
self.stdout = self.process.stdout
self.stderr = self.process.stderr
self.pid = self.process.pid

def __del__(self):
self.process = None

def communicate(self):
return self.process.communicate()

def poll(self):
return self.process.poll()

def terminate(self):
"Python version < 2.6 doesn't have a terminate method for subprocess"
if PYTHON_VERSION[0] == 2 and PYTHON_VERSION[1] >= 6:
return self.process.terminate()
else:
signal = 15
return os.kill(self.pid, signal)

def stop(self):
signal = 19
if PYTHON_VERSION[0] == 2 and PYTHON_VERSION[1] >= 6:
return self.process.send_signal(signal)
else:
return os.kill(self.pid, signal)

def resume(self):
signal = 18
if PYTHON_VERSION[0] == 2 and PYTHON_VERSION[1] >= 6:
return self.process.send_signal(signal)
else:
return os.kill(self.pid, signal)
39 changes: 39 additions & 0 deletions TempfileWrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##
# Project: gespeaker - A GTK frontend for espeak
# Author: Muflone Ubuntu Trucchi <[email protected]>
##

import tempfile
import sys
import os

PYTHON_VERSION = sys.version_info[0:2]

class NamedTemporaryFile(object):
"Replacement for NamedTemporaryFile compatible with python 2.5"
def __init__(self, mode='w+b', delete=True):
self.delete = delete
if PYTHON_VERSION[0] == 2 and PYTHON_VERSION[1] >= 6:
self.tempfile = tempfile.NamedTemporaryFile(mode=mode, delete=delete)
self.name = self.tempfile.name
else:
# Python < 2.6 doesn't have a delete argument for NamedTemporaryFile
# We have to proceed manually :-\
self.name = tempfile.mkstemp()[1]
self.tempfile = open(self.name, mode=mode)

def __del__(self):
self.close()
self.tempfile = None

def write(self, data):
"Write data to the temporary file"
return self.tempfile.write(data)

def close(self):
"Close the temporary file and delete it if requested"
ret = self.tempfile.close()
if PYTHON_VERSION[0] == 2 and PYTHON_VERSION[1] < 6 and self.delete:
# Manually deletion of temporary filename
os.remove(self.name)
return ret
14 changes: 14 additions & 0 deletions gespeaker.glade.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
char *s = N_("<b>Insert text to play</b>");
char *s = N_("<b>Settings</b>");
char *s = N_("Dela_y:");
char *s = N_("Fem_ale");
char *s = N_("P_itch:");
char *s = N_("Spee_d:");
char *s = N_("Voice:");
char *s = N_("Welcome in Gespeaker");
char *s = N_("_Edit");
char *s = N_("_File");
char *s = N_("_Help");
char *s = N_("_Language:");
char *s = N_("_Male");
char *s = N_("_Volume:");
Loading

0 comments on commit 586d98d

Please sign in to comment.