示例#1
0
 def generate_sound(dest, lang, text):
     """
     Creates a mp3 sound to be reused
     :string filename:Name of the file to be created
     :string lang:two letter representation of the language
     :string text:the content to be read in the mp3 file
     """
     language = lang.lower()
     print "Creating {}".format(dest)
     GoogleTTS.audio_extract(text, {"language": language, "output": dest})
示例#2
0
 def listen(self):
     # retrieve from google possible responses
     self.ready_response = GoogleTTS.audio_extract(self.config.get("recognizer", "ready_response"))
     self.keyword_ack_response = GoogleTTS.audio_extract(self.config.get("recognizer", "keyword_ack"))
     self.command_ack_response = GoogleTTS.audio_extract(self.config.get("recognizer", "command_ack"))
     self.lookup_error_response = GoogleTTS.audio_extract(self.config.get("recognizer", "lookup_error_response"))
     self.playMp3(self.ready_response)
     
     # wait forever
     keyword_mode = True and not self.force_command
     while True:
         audio = self._captureVoice()
         keyword_mode = self._processVoice(audio, keyword_mode)
示例#3
0
    def listen(self):
        # retrieve from google possible responses
        self.ready_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "ready_response"))
        self.keyword_ack_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "keyword_ack"))
        self.command_ack_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "command_ack"))
        self.lookup_error_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "lookup_error_response"))
        self.playMp3(self.ready_response)

        # wait forever
        keyword_mode = True and not self.force_command
        while True:
            audio = self._captureVoice()
            keyword_mode = self._processVoice(audio, keyword_mode)
示例#4
0
    def listen_multi(self):
        """ multi-threading option for listening to commands """
        # retrieve from google possible responses
        self.ready_response = GoogleTTS.audio_extract(self.config.get("recognizer", "ready_response"))
        self.keyword_ack_response = GoogleTTS.audio_extract(self.config.get("recognizer", "keyword_ack"))
        self.command_ack_response = GoogleTTS.audio_extract(self.config.get("recognizer", "command_ack"))
        self.lookup_error_response = GoogleTTS.audio_extract(self.config.get("recognizer", "lookup_error_response"))
        self.playMp3(self.ready_response)
        self.voiceQueue = deque()     # initialize to an empy queue
        self.thread_lock = thread.allocate_lock()
        
        # starts the 2 threads
        thread.start_new_thread(self.captureVoice, ())
        thread.start_new_thread(self.processVoice, ())

        # wait forever
        while True:
            time.sleep(1)
示例#5
0
def say_something(something):
    """Use google tts to translate something to voice played by mpg123"""
    if mpg_player is None:
        logging.error("mpg123 is not installed.")
        return

    import GoogleTTS
    audio_data = GoogleTTS.audio_extract(something)
    process = subprocess.Popen([mpg_player, "--quiet", "-"], stdin=subprocess.PIPE)
    process.communicate(audio_data)
示例#6
0
def say_something(something):
    """Use google tts to translate something to voice played by mpg123"""
    if mpg_player is None:
        logging.error("mpg123 is not installed.")
        return

    import GoogleTTS
    audio_data = GoogleTTS.audio_extract(something)
    process = subprocess.Popen([mpg_player, "--quiet", "-"],
                               stdin=subprocess.PIPE)
    process.communicate(audio_data)
示例#7
0
    def listen_multi(self):
        """ multi-threading option for listening to commands """
        # retrieve from google possible responses
        self.ready_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "ready_response"))
        self.keyword_ack_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "keyword_ack"))
        self.command_ack_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "command_ack"))
        self.lookup_error_response = GoogleTTS.audio_extract(
            self.config.get("recognizer", "lookup_error_response"))
        self.playMp3(self.ready_response)
        self.voiceQueue = deque()  # initialize to an empy queue
        self.thread_lock = thread.allocate_lock()

        # starts the 2 threads
        thread.start_new_thread(self.captureVoice, ())
        thread.start_new_thread(self.processVoice, ())

        # wait forever
        while True:
            time.sleep(1)
示例#8
0
    def get_tts(self, input_text, delete_file=False, **args):
        """
        Get TTS voice mp3 from Google
        get_tts(input_text='tunnel snakes rule apparently', args = {'language':'en','output':'outputto.mp3'})

        Robot Framework:
        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        | UiTestLib.Get TTS    |   Hello world    |   False   |    output=ooo.mp3   |   language=en |
        """
        print "Get text to speech: ", input_text
        downloaded = False
        if str(delete_file) == 'True':
            if os.path.exists(args['output']):
                os.remove(args['output'])
        if os.path.exists(args['output']):
            if os.path.getsize(args['output']) <= 0:
                os.remove(args['output'])
        if args['output'] is not None:
            if not os.path.exists(args['output']):
                print 'Generating mp3 file......', args['output']
                downloaded = GoogleTTS.audio_extract(input_text, args)
            else:
                print 'Have same local file'
                downloaded = True
        if not downloaded:
            print "Downloaded TTS from Google failed, trying to download from local FTP..."
            mp3file = open(args['output'], 'w')
            mp3url = 'ftp://cnbjlx9548/atautomation/Test-Content/Croft/' + args[
                'output']
            try:
                resp = urllib2.urlopen(mp3url, timeout=40)
                mp3file.write(resp.read())
                time.sleep(.05)
            except Exception, e:
                print e
                return False
            mp3file.close()
示例#9
0
    def get_tts(self, input_text, delete_file=False, **args):
        """
        Get TTS voice mp3 from Google
        get_tts(input_text='tunnel snakes rule apparently', args = {'language':'en','output':'outputto.mp3'})

        Robot Framework:
        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        | UiTestLib.Get TTS    |   Hello world    |   False   |    output=ooo.mp3   |   language=en |
        """
        print "Get text to speech: ", input_text
        downloaded = False
        if str(delete_file) == "True":
            if os.path.exists(args["output"]):
                os.remove(args["output"])
        if os.path.exists(args["output"]):
            if os.path.getsize(args["output"]) <= 0:
                os.remove(args["output"])
        if args["output"] is not None:
            if not os.path.exists(args["output"]):
                print "Generating mp3 file......", args["output"]
                downloaded = GoogleTTS.audio_extract(input_text, args)
            else:
                print "Have same local file"
                downloaded = True
        if not downloaded:
            print "Downloaded TTS from Google failed, trying to download from local FTP..."
            mp3file = open(args["output"], "w")
            mp3url = "ftp://cnbjlx9548/atautomation/Test-Content/Croft/" + args["output"]
            try:
                resp = urllib2.urlopen(mp3url, timeout=40)
                mp3file.write(resp.read())
                time.sleep(0.05)
            except Exception, e:
                print e
                return False
            mp3file.close()
示例#10
0
 def saySomething(self, something):
     self.playMp3(GoogleTTS.audio_extract(something))
示例#11
0
 def saySomething(self, something):
     self.playMp3(GoogleTTS.audio_extract(something))