예제 #1
0
 def speak(self, s):
     """
     TODO: refactor
     """
     if self.mode == "festival":
         festival.sayText(s)
         return
     tts = gTTS(text=s, lang='en')
     tts.save("speech.mp3")
     if self.mode == "pyglet":
         song = pyglet.media.load('speech.mp3')
         song.play()
         # TODO fix for multiple files
     elif self.mode == "pygame":
         clock = pygame.time.Clock()
         pygame.mixer.music.load("speech.mp3")
         pygame.mixer.music.play()
         while pygame.mixer.music.get_busy():
             clock.tick(1000)
             continue
     else:
         raise Exception("Mode not found!")
         os.remove("speech.mp3")
     os.remove("speech.mp3")
     return True
예제 #2
0
 def sayText(self, text):
     useFestival = False
     if useFestival:
         import festival
         festival.sayText(text)
     else:
         self.soundhandle.voiceSound(text).play()
예제 #3
0
def main(options, args):
    address = options.ensure_value('address', None)
    status_to = options.ensure_value('status_to', None)
    assert address and status_to

    context = zmq.Context()
    sock = context.socket(zmq.PAIR)
    sock.bind(address)
    status_sock = context.socket(zmq.PUSH)
    status_sock.connect(status_to)
    while True:
        print 'Waiting...'
        sys.stdout.flush()
        task = sock.recv_json()
        print 'Task: %s' % task
        sys.stdout.flush()
        if task['action'] == 'say':
            status_sock.send_json({
                'sender': 'lip_service',
                'status': 'speaking'
            })
            festival.sayText(task['text'])
            time.sleep(0.125)
            status_sock.send_json({
                'sender': 'lip_service',
                'status': 'waiting'
            })
예제 #4
0
    def _run(self):
        """
        The actual worker thread.
        """
        # Festival is a little hokey and so we need to start it in the same
        # thread that we use it. Otherwise we get an message saying:
        #  SIOD ERROR: the currently assigned stack limit has been exceeded
        # As such we need to do everything here and communicate back success or
        # failure to the _start() method via member variables. Lovely.
        try:
            import festival
            festival.execCommand(self._voice)
            self._boot_strapped = True
        except Exception as e:
            self._start_error = e
            return

        # Keep going until we're told to stop
        while self.is_running:
            if len(self._queue) == 0:
                time.sleep(0.1)
                continue

            # Else we have something to say
            try:
                # Get the text, make sure that '"'s in it won't confuse things
                start = time.time()
                text = self._queue.pop()
                text = text.replace('"', '')

                # Festvial pauses for too long with commas so just ignore them
                text = text.replace(',', '')

                # Ignore empty strings
                if not text:
                    LOG.info("Nothing to say...")
                    continue

                # We're about to say something, clear any interrupted flag ready
                # for any new one
                self._interrupted = False

                # We're talking so mark ourselves as active accordingly
                self._notify(Notifier.WORKING)

                # Break up the text into bits and say them so that we can
                # interrupt the output. Then say each non-empty part. We break
                # on natural pauses in the speech.
                for part in re.split(r'[\.,;:]', text):
                    if self._interrupted:
                        break
                    if part:
                        festival.sayText(part)

            except Exception as e:
                LOG.error("Failed to say '%s': %s" % (text, e))

            finally:
                self._notify(Notifier.IDLE)
예제 #5
0
파일: tts.py 프로젝트: kwendim/SHUC
 def tts_callback(self, text):
     rospy.logwarn(text.data)
     if self.tts_type == "espeak":
         espeak.synth(text.data)
     elif self.tts_type == "festival":
         festival.sayText(txt)
     elif self.tts_type == "mimic":
         subprocess.call(["mimic", "-t", txt])
     else:
         rospy.logwarn("PLEASE SELECT A TTS")
예제 #6
0
def main():
    args = build_parser().parse_args()
    festival.setStretchFactor(args.period)
    while True:
        line = sys.stdin.readline()
        if line == '':
            break
        print(line, end='')
        if (not args.regex) or any(re.search(r, line) for r in args.regex):
            festival.sayText(line.decode('utf8').encode('ascii', errors='replace'))
예제 #7
0
def speak_ICAO():
    target = raw_input("Enter a file name: ")
    fhand = open(target)
    text = fhand.read().lower()

    for char in text:
        speech = ""
        speech = d.get(char, char)

        festival.sayText(speech)

        if char == " ":
            time.sleep(1.5)
        else:
            time.sleep(0.5)

    return speech
예제 #8
0
def speak_ICAO():
    target = raw_input("Enter a file name: ")
    fhand = open(target)
    text = fhand.read().lower()

    for char in text:
        speech = ""
        speech = d.get(char, char)

        festival.sayText(speech)

        if char == " ":
            time.sleep(1.5)
        else:
            time.sleep(0.5)

    return speech
예제 #9
0
    def main1(self):

        # Keep playing until we're out of tiles or solutions.
        self.count+=1
        # Fill up our rack.
        print "Bag: %s" % "".join(self.bag)
        self.old_rack = self.rack

        # Updates rack with current rack from video feed.
        # cam1 = cv2.VideoCapture(1)
        # print cam1.isOpened()
        self.cam1 = 1
        self.rack1 = rack_vision.get_rack(self.classify,self.cam1)
        self.rack2 = rack_vision.get_rack(self.classify,self.cam1)
        iteration = 0
        while (not (self.rack1 in self.rack2)) and iteration <=6:
            self.rack1 = rack_vision.get_rack(self.classify,self.cam1)
            self.rack2 = rack_vision.get_rack(self.classify,self.cam1)
            iteration += 1

        self.rack = self.rack1
        self.gui.show_rack(self.rack)

        # cam1.release()
        cv2.destroyAllWindows()

        print("RACK:")
        print(self.rack)

        # Get a list of possible solutions. These aren't all necessarily legal.
        self.solutions = self.board.generate_solutions(self.rack, self.dictionary)


        # self.solution = self.board.find_best_solution(self.solutions, self.dictionary)

        self.solution = self.board.solution_curve(self.solutions,self.dictionary,self.mode,self.count)
        #print('SOLUTIONSSSS %s' %self.solutions)

        self.gui.addword(self.solution.word,self.solution.col,self.solution.row,self.solution.direction,suggestion = True)
        festival.sayText("I think you should play")
        festival.setStretchFactor(1.4)
        festival.sayText(self.solution.word)
예제 #10
0
    def main3(self): 
        print self.update_board
        print self.old_board
        self.move,self.letter_placed_on_board = self.board.get_played_word(self.update_board,self.old_board,self.dictionary)

        print ("The word:"+ self.move.word +"was just played.")

        for char in self.letter_placed_on_board:
            self.rack = self.rack.replace(char,"")

        #rack_list = self.letter_placed_on_board.split()
        self.move.rack_indices = self.letter_placed_on_board
        self.board.add_solution(self.move)

        if (self.move.word == self.solution.word):
            print("Player listened to Baxter")
        else:
            print("defied Baxter")

        if (self.move.score != None):
            self.my_score+=self.move.score
            if len(self.move.rack_indices) == 7:
                self.my_score+=50

        print "Baxter's Score: %d" % self.my_score
        festival.setStretchFactor(1)
        festival.sayText("Good Move")
        self.gui.log.write('Good job, your score is now: ' + str(self.my_score))

        #generate_rack(self.rack,self.old_rack,self.bag)

        for char in self.letter_placed_on_board:
            self.rack = self.rack.replace(char,"")
        self.old_board = Board()
        self.old_board.set_cells(self.update_board.cells)
        print 'oldboard set to'
        print self.old_board
        print ("count:"+str(self.count))
예제 #11
0
    def main0(self):

        #gui = ScrabbleGUI.UserInterface()

        # Load the dictionary.
        self.dictionary = Dictionary.load(DICTIONARY_FILENAME)
        self.board = Board()

        # Keep track of the winning solution at each round.
        self.winners = []

        # List of letters we can still pick from.
        self.bag = get_full_bag()

        # Rack starts out empty. Keep track of current and last rack state.
        self.rack = ""
        self.old_rack = ""
        self.count = 0

        # Keep track of current and last board state,
        self.update_board = None
        self.old_board = Board()

        # Baxter's score
        self.my_score = 0

        #Create classifier
        self.classify = CNN_Model()

        # set Baxter's mode.
        # mode = 0: skill level tapers off and stays low
        # mode = 1: skill level tapers off and increases after reaching lowest point
        # mode = 2: highest skill level for whole game 
        self.mode = 0

        festival.setStretchFactor(1)
        festival.sayText("Hello, it is Baxter here, I hope we do well")
예제 #12
0
    def endpoint_dispatch(self, endpoint: EndpointDefinition, message: Message,
                          now: datetime):
        try:
            if not self.matches(endpoint.match_definition, message):
                return False

            if not self.scheduled(endpoint.schedule, now) or not self.displayed(endpoint.windowing) \
             or not self.cams(endpoint.camera, self.camera_device_map):
                return True

            original_text = "%s :: %s" % (message.summary, message.body)
            plain = BeautifulSoup(original_text, "lxml")
            text = self.apply_templates(endpoint.templates, plain.text)
            sound = endpoint.sound
            if endpoint.max_len is not None:
                text = text[:endpoint.max_len]
            channels = self.default.channels if not endpoint.channels else endpoint.channels

            if Channel.LOG in channels:
                line = "Received notification via '%s' - %s" % (message.name, text) if text == original_text else \
                 "Received and transformed notification via '%s' - %s (was '%s')" % (message.name, text, original_text)
                announce.info(line)

            if Channel.DICTATION in channels:
                if sound is not None:
                    sound.play()
                festival.sayText(text)

            return True

        except BaseException as err:
            logging.error(
                "Exception processing endpoint definition for %s - %s",
                endpoint.name, err)
            traceback.print_exc()
            return False
예제 #13
0
파일: tts.py 프로젝트: tb0hdan/voiceplay
 def __say_linux(message):
     """
     Read message aloud (Linux)
     """
     from festival import sayText  # pylint:disable=import-error
     sayText(message)
예제 #14
0
파일: test.py 프로젝트: yvt/pyfestival
 def test_say_text(self):
     self.assertTrue(festival.sayText("test one"))
     self.assertTrue(festival._festival._sayText("test two"))
예제 #15
0
import festival

festival.sayText("I am Raspberry Pi")
festival.sayFile("ch05_test_tts.txt")

예제 #16
0
파일: voice.py 프로젝트: alfem/minidron
 def say(self,text):
   festival.sayText(text)
예제 #17
0
    # raw detection code
    gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY, dstCn=0)
    pil = Image.fromarray(gray)
    width, height = pil.size
    raw = pil.tobytes()

    # create a reader
    image = zbar.Image(width, height, 'Y800', raw)
    scanner.scan(image)

    # extract results
    for symbol in image:
        # do something useful with results
        streeng = "decoded " + str(symbol.type) + " symbol " + str(symbol.data)
        print streeng
        festival.sayText(streeng)

    # show the frame
    cv2.imshow("#iothack15", output)

    # clear stream for next frame
    rawCapture.truncate(0)

    # Wait for the magic key
    keypress = cv2.waitKey(1) & 0xFF
    if keypress == ord('q'):
    	break

# When everything is done, release the capture
camera.close()
cv2.destroyAllWindows()
예제 #18
0
 def test_say_text(self):
     self.assertTrue(festival.sayText("test one"))
     self.assertTrue(festival._festival._sayText("test two"))
예제 #19
0
파일: voice.py 프로젝트: alfem/minidron
 def say(self, text):
     festival.sayText(text)