Esempio n. 1
0
 def getWavStream(self,text):
     wav_path = os.path.join(util.getTmpfs(),'speech.wav')
     mp3_path = os.path.join(util.getTmpfs(),'speech.mp3')
     self.runCommand(text,mp3_path)
     self.process = subprocess.Popen(['mpg123','-w',wav_path,mp3_path],stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
     while self.process.poll() == None and self.active: util.sleep(10)
     os.remove(mp3_path)
     return open(wav_path,'rb')
Esempio n. 2
0
    def play(self, path):
        args = self.playArgs(path)
        self._wavProcess = subprocess.Popen(args,
                                            stdout=(open(os.path.devnull,
                                                         'w')),
                                            stderr=subprocess.STDOUT)

        while self._wavProcess.poll() == None and self.active:
            util.sleep(10)
Esempio n. 3
0
 def play(self,path):
     if not os.path.exists(path):
         util.LOG('WindowsAudioPlayer.play() - Missing wav file')
         return
     self.audio = self._player.load(path)
     self.audio.play()
     self.event.clear()
     self.event.wait(self.audio.milliseconds() / 1000.0)
     if self.event.isSet(): self.audio.stop()
     while self.audio.isplaying(): util.sleep(10)
     self.audio = None
Esempio n. 4
0
	def play(self,path):
		if not os.path.exists(path):
			util.LOG('WindowsAudioPlayer.play() - Missing wav file')
			return
		self.audio = self._player.load(path)
		self.audio.play()
		self.event.clear()
		self.event.wait(self.audio.milliseconds() / 1000.0)
		if self.event.isSet(): self.audio.stop()
		while self.audio.isplaying(): util.sleep(10)
		self.audio = None
Esempio n. 5
0
 def getWavStream(self, text):
     wav_path = os.path.join(util.getTmpfs(), 'speech.wav')
     mp3_path = os.path.join(util.getTmpfs(), 'speech.mp3')
     self.runCommand(text, mp3_path)
     self.process = subprocess.Popen(['mpg123', '-w', wav_path, mp3_path],
                                     stdout=(open(os.path.devnull, 'w')),
                                     stderr=subprocess.STDOUT)
     while self.process.poll() == None and self.active:
         util.sleep(10)
     os.remove(mp3_path)
     return open(wav_path, 'rb')
Esempio n. 6
0
 def __init__(self):
     self.SpVoice = None
     self.comtypesClient = None
     self.valid = False
     self._voiceName = None
     self.interrupt = False
     try:
         self.reset()
     except:
         util.ERROR('SAPI: Initialization failed: retrying...')
         util.sleep(1000) #May not be necessary, but here it is
         try:
             self.reset()
         except:
             util.ERROR('SAPI: Initialization failed: Giving up.')
             return
     self.valid = True
     self.COMError = importHelper('_ctypes').COMError
     self.setStreamFlags()
Esempio n. 7
0
        return None

    def checkSAPI(func):
        def checker(self,*args,**kwargs):
            if not self.valid:
                util.LOG('SAPI: Broken - ignoring {0}'.format(func.__name__))
                return None
            try:
                return func(self,*args,**kwargs)
            except self.COMError,e:
                self.logSAPIError(e,func.__name__)
            except:
                util.ERROR('SAPI: {0} error'.format(func.__name__))
            self.valid = False
            util.LOG('SAPI: Resetting...')
            util.sleep(1000)
            try:
                self.reset()
                self.valid = True
                util.LOG('SAPI: Resetting succeded.')
                return func(self,*args,**kwargs)
            except self.COMError,e:
                self.valid = False
                self.logSAPIError(e,func.__name__)
            except:
                self.valid = False
                util.ERROR('SAPI: {0} error'.format(func.__name__))

        return checker

    #Wrapped SAPI methods
Esempio n. 8
0
 def threadedSay(self, text):
     if not text:
         return
     self.process = subprocess.Popen(["say", text.encode("utf-8")])
     while self.process.poll() == None and self.active:
         util.sleep(10)
Esempio n. 9
0
        self._wavProcess = subprocess.Popen(self._pipeArgs,
                                            stdin=subprocess.PIPE,
                                            stdout=(open(os.path.devnull,
                                                         'w')),
                                            stderr=subprocess.STDOUT)
        try:
            shutil.copyfileobj(source, self._wavProcess.stdin)
        except IOError, e:
            if e.errno != errno.EPIPE:
                util.ERROR('Error piping audio', hide_tb=True)
        except:
            util.ERROR('Error piping audio', hide_tb=True)
        source.close()
        self._wavProcess.stdin.close()
        while self._wavProcess.poll() == None and self.active:
            util.sleep(10)

    def setSpeed(self, speed):
        self.speed = speed

    def setVolume(self, volume):
        self.volume = volume

    def play(self, path):
        args = self.playArgs(path)
        self._wavProcess = subprocess.Popen(args,
                                            stdout=(open(os.path.devnull,
                                                         'w')),
                                            stderr=subprocess.STDOUT)

        while self._wavProcess.poll() == None and self.active:
Esempio n. 10
0
    def play(self,path):
        args = self.playArgs(path)
        self._wavProcess = subprocess.Popen(args,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)

        while self._wavProcess.poll() == None and self.active: util.sleep(10)
Esempio n. 11
0
    def runCommandAndSpeak(self, text):
        args = ['termux-tts-speak', text]

        process = subprocess.Popen(args)
        while process.poll() == None and self.active:
            util.sleep(10)
Esempio n. 12
0
        util.LOG_DEBUG ("SubprocessAudioPlayer.pipe: after adding _soundOutputArgs pipeArgs={}".format (pipeArgs))

        #self._wavProcess = subprocess.Popen(self._pipeArgs,stdin=subprocess.PIPE,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
        self._wavProcess = subprocess.Popen(pipeArgs,stdin=subprocess.PIPE,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
        ##########

        try:
            shutil.copyfileobj(source,self._wavProcess.stdin)
        except IOError,e:
            if e.errno != errno.EPIPE:
                util.ERROR('Error piping audio',hide_tb=True)
        except:
            util.ERROR('Error piping audio',hide_tb=True)
        source.close()
        self._wavProcess.stdin.close()
        while self._wavProcess.poll() == None and self.active: util.sleep(10)

    def setSpeed(self,speed):
        self.speed = speed

    def setVolume(self,volume):
        self.volume = volume

    def play(self,path):
        args = self.playArgs(path)
        self._wavProcess = subprocess.Popen(args,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)

        while self._wavProcess.poll() == None and self.active: util.sleep(10)

    def isPlaying(self):
        return self._wavProcess and self._wavProcess.poll() == None
Esempio n. 13
0
		
	def canPipe(self):
		return bool(self._pipeArgs)
		
	def pipe(self,source):
		self._wavProcess = subprocess.Popen(self._pipeArgs,stdin=subprocess.PIPE,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
		try:
			shutil.copyfileobj(source,self._wavProcess.stdin)
		except IOError,e:
			if e.errno != errno.EPIPE:
				util.ERROR('Error piping audio',hide_tb=True)
		except:
			util.ERROR('Error piping audio',hide_tb=True)
		source.close()
		self._wavProcess.stdin.close()
		while self._wavProcess.poll() == None and self.active: util.sleep(10)
		
	def setSpeed(self,speed):
		self.speed = speed
		
	def setVolume(self,volume):
		self.volume = volume
		
	def play(self,path):
		args = self.playArgs(path)
		self._wavProcess = subprocess.Popen(args,stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
		
		while self._wavProcess.poll() == None and self.active: util.sleep(10)
		
	def isPlaying(self):
		return self._wavProcess and self._wavProcess.poll() == None
Esempio n. 14
0
    def insertPause(self,ms=500):
        """Insert a pause of ms milliseconds

        May be overridden by sublcasses. Default implementation sleeps for ms.
        """
        util.sleep(ms)
Esempio n. 15
0
 def threadedSay(self, text):
     if not text: return
     self.process = subprocess.Popen(['say', text.encode('utf-8')])
     while self.process.poll() == None and self.active:
         util.sleep(10)
Esempio n. 16
0
 def runCommandAndSpeak(self,text):
     args = ['recite',text]
     self.process = subprocess.Popen(args)
     while self.process.poll() == None and self.active: util.sleep(10)
Esempio n. 17
0
 def threadedSay(self, text):
     if not text: return
     self.synth.startSpeakingString_(self.cocoapy.get_NSString(text))
     while self.synth.isSpeaking():
         util.sleep(10)
Esempio n. 18
0
    def insertPause(self, ms=500):
        """Insert a pause of ms milliseconds

        May be overridden by sublcasses. Default implementation sleeps for ms.
        """
        util.sleep(ms)
Esempio n. 19
0
 def threadedSay(self, text):
     if not text:
         return
     self.synth.startSpeakingString_(self.cocoapy.get_NSString(text))
     while self.synth.isSpeaking():
         util.sleep(10)
Esempio n. 20
0
 def runCommandAndSpeak(self,text):
     self.process = subprocess.Popen(['flite', '-voice', self.voice, '-t', text.encode('utf-8')])
     while self.process.poll() == None and self.active: util.sleep(10)
Esempio n. 21
0
 def runCommandAndSpeak(self, text):
     self.process = subprocess.Popen(
         ['flite', '-voice', self.voice, '-t',
          text.encode('utf-8')])
     while self.process.poll() == None and self.active:
         util.sleep(10)