Example #1
0
def detected_callback():
    print("hotword detected")
    text = "Bonjour monsieur. Comment allez-vous ?"
    lang = "fr"
    speech = Speech(text, lang)
    sox_effects = ("speed", "1.1")
    speech.play(sox_effects)
Example #2
0
def readText(text):
    """
	Lee un texto
	"""
    lang = "es"
    speech = Speech(text, lang)
    speech.play()
Example #3
0
def callback(recognizer, audio):
    print("callback")
    # received audio data, now we'll recognize it using Google Speech Recognition
    try:
        # for testing purposes, we're just using the default API key
        # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
        # instead of `r.recognize_google(audio)`
        said = recognizer.recognize_google(audio, language="fr-FR")
        print("Google Speech Recognition thinks you said " + mytext)

        if said == 'stop':
            # calling this function requests that the background listener stop listening
            stop_listening(wait_for_stop=False)
            print('the end')
        else:
            speech = Speech(said, "fr")
            sox_effects = ("speed", "1.1")
            speech.play(sox_effects)

    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print(
            "Could not request results from Google Speech Recognition service; {0}"
            .format(e))
Example #4
0
    def _hablar(self, mensaje: str) -> None:
        """
        Usa Google Speech para hablar al usuario con una frase aleatoria.
        """

        habla = Speech(mensaje, 'es')
        habla.play()
Example #5
0
def speak_object_changes(speech_flag, object_changes, height, width):
    global speech_out_array
    global old_speech_out_array
    old_speech_out_array = speech_out_array
    speech_out_array = []

    for key, object_change in object_changes.items():
        speech_out_str = key
        if "person_name" in object_change:
            speech_out_str = object_change["person_name"]

        if object_change["appeared"] is True:
            speech_out_str += " entered frame at "
            speech_out_str += get_object_position_words(
                object_change["bbox"], height, width)
        elif object_change["disappeared"] is True:
            speech_out_str += " left frame"
        else:
            speech_out_str += " moved to "
            speech_out_str += get_object_position_words(
                object_change["bbox"], height, width)
        speech_out_array.append(speech_out_str)

    output_array = []
    for speech in speech_out_array:

        if speech not in old_speech_out_array:
            output_array.append(speech)

            if speech_flag is True:
                speech = Speech(speech_out_str, LANG)
                speech.play(sox_effects)
    return output_array
Example #6
0
def notice(text, lang='vi'):
    try:
        speech = Speech(text, lang)
        speech.play()
    except Exception:
        print(text)
        print('No network connect! So i can not speak for you!')
Example #7
0
def response(sentence, userID='123', show_details=False):
    results = classify(sentence)
    # if we have a classification then find the matching intent tag
    if results:
        # loop as long as there are matches to process
        while results:
            for i in intents['intents']:
                # find a tag matching the first result
                if i['tag'] == results[0][0]:
                    # set context for this intent if necessary
                    if 'context_set' in i:
                        if show_details: print('context:', i['context_set'])
                        context[userID] = i['context_set']

                    # check if this intent is contextual and applies to this user's conversation
                    if not 'context_filter' in i or \
                        (userID in context and 'context_filter' in i and i['context_filter'] == context[userID]):
                        if show_details: print('tag:', i['tag'])
                        val = random.choice(i['responses'])
                        speech = Speech(val, lang)
                        sox_effects = ("speed", "1.0")
                        speech.play(sox_effects)
                        # a random response from the intent
                        return print(val)

            results.pop(0)
Example #8
0
def textToSpeech(text):
    lang = 'en-US'
    lang = lang.replace('-','_')

    speech = Speech(text, lang)
    sox_effects = ("speed", "1.0")
    sox_effects = ("vol", "0.5")
    speech.play(sox_effects)
Example #9
0
def say(text, speed=1.5, lang='en'):
    try:
        speech = Speech(text.replace('\n', ''), lang)
        speech.play()

        sox_effects = ('speed', speed)
        speech.play(sox_effects)
    except TypeError:
        print('Could not read {}'.format(text))
Example #10
0
 def warning_notification(self, text):
     print(dt.datetime.now().strftime('%b %d, %H:%M:%S'), text)
     while self.warning_notification_output:
         time.sleep(0.5)
     self.warning_notification_output = True
     speech = Speech(text, 'en')
     speech.play()
     time.sleep(3)
     self.warning_notification_output = False
Example #11
0
def textToSpeech(text):
    # lang = 'ko_KR'
    global lang
    lang = lang.replace('-','_')

    speech = Speech(text, lang)
    sox_effects = ("speed", "1.0")
    sox_effects = ("vol", "0.05")
    speech.play(sox_effects)
Example #12
0
def update_output(n_clicks, value):
    vocab_data = data_loader.get_question_answer_vocab("2")
    qvocab = vocab_data['question_vocab']
    q_map = { vocab_data['question_vocab'][qw] : qw for qw in vocab_data['question_vocab']}
    print('filename::',filen)
    fc7_features = utils.extract_fc7_features(filen, 'Data/vgg16.tfmodel')
    model_options = {
		'num_lstm_layers' : 2,
		'rnn_size' : 512,
		'embedding_size' : 512,
		'word_emb_dropout' : 0.5,
		'image_dropout' : 0.5,
		'fc7_feature_length' : 4096,
		'lstm_steps' : vocab_data['max_question_length'] + 1,
		'q_vocab_size' : len(vocab_data['question_vocab']),
		'ans_vocab_size' : len(vocab_data['answer_vocab'])
	}
    
    question_vocab = vocab_data['question_vocab']
    word_regex = re.compile(r'\w+')
    question_ids = np.zeros((1, vocab_data['max_question_length']), dtype = 'int32')
    print('qst',value)
    question_words = re.findall(word_regex, value)
    base = vocab_data['max_question_length'] - len(question_words)
    for i in range(0, len(question_words)):
        if question_words[i] in question_vocab:
            question_ids[0][base + i] = question_vocab[ question_words[i] ]
        else:
            question_ids[0][base + i] = question_vocab['UNK']
    ans_map = { vocab_data['answer_vocab'][ans] : ans for ans in vocab_data['answer_vocab']}
    model = vis_lstm_model.Vis_lstm_model(model_options)
    input_tensors, t_prediction, t_ans_probab = model.build_generator()
    sess = tf.InteractiveSession()
    saver = tf.train.Saver()
    saver.restore(sess, 'Data/Models/modelnew99.ckpt')
    pred, answer_probab = sess.run([t_prediction, t_ans_probab], feed_dict={
        input_tensors['fc7']:fc7_features,
        input_tensors['sentence']:question_ids,
    })
    print("answerprediction",pred[0])
    #model.summary()
    #plot_model(model,to_file='predictmodel.png')
    print ("Ans:", ans_map[pred[0]])
    answer_probab_tuples = [(-answer_probab[0][idx], idx) for idx in range(len(answer_probab[0]))]
    answer_probab_tuples.sort()
    print ("Top Answers")
    for i in range(1):
        print (ans_map[ answer_probab_tuples[0][1] ])
        #ans=(ans_map[answer_probab_tuples[i][1] ])
        lang = "en"
        text="This is a "+ans_map[ answer_probab_tuples[0][1] ]
        speech = Speech(text, lang)

        sox_effects = ("speed", "0.8")
        speech.play(sox_effects)
        
    return ans_map[answer_probab_tuples[0][1]]
Example #13
0
def read(message, print_text=True):
    speech = Speech(message, LANGUAGE)
    if print_text:
        cprint('\n' * (rows // 2) + ' ' * ((columns // 2) -
                                           (len(message) // 2)) + message,
               'red',
               attrs=['bold'])
    sox_effects = ("speed", "1.")
    speech.play(sox_effects)
Example #14
0
 def wrapper(*args, **kwargs):
     t1 = time.time()
     out = fun(*args, **kwargs)
     t2 = time.time()
     text = "It took " + str((t2 - t1)) + " to run the function."
     print(text)
     speech = Speech(text, lang)
     speech.play(None)
     return out
Example #15
0
def speach(request, id):

    phrase = Phrase.objects.get(pk=id)

    speech = Speech(phrase.original, "en")
    sox_effects = ("speed", "1")
    speech.play(sox_effects)

    return HttpResponse('Speach')
Example #16
0
def say():
    lang = 'en'
    if request.method == 'POST':
        text = request.args.get('text')
        lang = request.args.get('lang')
        speech = Speech(text, lang)
        speech.play()
        return "pyTalk said {}!".format(text)
    else:
        return "pyTalk say works only on POST"
Example #17
0
def textToSpeech(request):
    text = request.GET.get("text", "")
    lang = "ur"
    translation = database.child("DataSet").order_by_key().limit_to_first(
        3).get()
    translator = Translator()
    translatorResult = translator.translate(text, src="en", dest="ur")
    speech = Speech(translatorResult.text, lang)
    sox_effects = ("speed", "1.0")
    speech.play(sox_effects)
    return HttpResponse("1")
def say(text=None):
    from google_speech import Speech

    if text is None:
        say_fortune()
    elif text.lower() == "flipkart":
        say_fk_fortune()
    else:
        lang = "en"
        speech = Speech(text, lang)
    speech.play()
Example #19
0
    def speak_and_save(self, text, path, index):
        speech = Speech(text, self.language)
        speech.play(sox_effects=("speed", DEFAULT_SPEED))

        if not os.path.isdir(path):
            os.mkdir(path)
            pass

        full_path = "{}/{}.mp3".format(path, index)
        print(full_path)
        speech.save(full_path)
Example #20
0
def shyna_speaks(msg: object) -> object:
    msgs = random.choice(msg.split("|"))
    for i in sent_tokenize(msgs):
        print(i)
        lang = "en"
        speech = Speech(i, lang)
        sox_effects = (
            "speed",
            "1",
        )
        speech.play(sox_effects)
Example #21
0
 def bookText(self, bookPath):
     if os.path.exists(bookPath):
         with open(bookPath, "rb") as file:
             pdf = PyPDF2.PdfFileReader(file)
             totalPages = pdf.getNumPages()
             pg = int(input(f"Enter page no. to read (1-{totalPages}): "))
             text = pdf.getPage(pg - 1).extractText()
             # print(text)
             if self.isOnline():
                 tts = Speech(text, "en")
                 tts.play()
             else:
                 print("Go Online for a better audio experience")
                 self.contentReader(text)
     else:
         print(f"Sorry no file found at {bookPath}")
Example #22
0
        def myfunc():
            self.is_speaking = True

            if self.speech_engine == 'not_set':
                if sys.platform == 'darwin':
                    self.speech_engine = 'mac'
                else:
                    self.speech_engine == 'google'

            if self.speech_engine == 'mac':
                subprocess.call(['say', '-v', speaker, sentence])
            elif self.speech_engine == 'google':
                speech = Speech(sentence, lang)
                speech.play(tuple())

            self.is_speaking = False
Example #23
0
        def myfunc():
            self.is_speaking = True

            if self.speech_engine == 'not_set':
                if sys.platform == 'darwin':
                    self.speech_engine = 'mac'
                else:
                    self.speech_engine == 'google'

            if self.speech_engine == 'mac':
                os.system('say -v {} "{}"'.format(speaker, sentence))
            elif self.speech_engine == 'google':
                speech = Speech(sentence, lang)
                speech.play(tuple())

            self.is_speaking = False
Example #24
0
def myspeech():
     r = sr.Recognizer()
     with sr.Microphone() as source:
         print("Listening...")
         r.pause_threshold = 1
         audio = r.listen(source)
     try:
        query = r.recognize_google(audio, language='fr-in')
        global vocale
        vocale = query.split()
     except sr.UnknownValueError:
        speech = Speech("je ne vous ai pas compris", "fr")
        speech.play()

        query = str(speech)

     return query
Example #25
0
def test(text):
    # reverberance
    sox_effects = ("reverb", "1.5")
    speech = Speech(text, "fr")
    speech.play((
        "speed",
        "1.2",
        "reverb",
        "80",
        "pitch",
        "-300",
        "pad",
        "1",
        "5",
        # "oops",
        #"lowpass", "100", "5"
    ))
Example #26
0
    def init_listener(self):
        try:
            print("A moment of silence, please...")
            with self.mic as source:
                self.r.adjust_for_ambient_noise(source)
            print("Set minimum energy threshold to {}".format(
                self.r.energy_threshold))
            while True:
                print("Listening!")
                with self.mic as source:
                    audio = self.r.listen(source)
                print("Got it! Now to recognize it...")
                try:
                    # recognize speech
                    value = self.r.recognize_google(audio)
                    #value = self.r.recognize_sphinx(audio)
                    print('val: ' + value)
                    value = value.lower().split()
                    # recognizing wake word and extracting from command
                    if value.pop(0) == 'hey' and value.pop(
                            0) == config.wake_word:
                        # we need some special handling here to correctly print unicode characters to standard output
                        value = ' '.join(value)
                        if str is bytes:  # this version of Python uses bytes for strings (Python 2)
                            print(u"You said {}".format(value).encode("utf-8"))
                            value = value.encode("utf-8")
                        else:  # this version of Python uses unicode for strings (Python 3+)
                            print("You said {}".format(value))
                        result = self.do_cmd(value)
                        if result:
                            lang = "en"
                            speech = Speech(result, lang)
                            sox_effects = ('speed', '1.0')
                            speech.play(sox_effects)
                            print(result)
                    else:
                        print('not a command')

                except sr.UnknownValueError:
                    print("Oops! Didn't catch that")
                except sr.RequestError as e:
                    print(
                        "Uh oh! Couldn't request results from Google Speech Recognition service; {0}"
                        .format(e))
        except KeyboardInterrupt:
            pass
Example #27
0
    def speak(self):
        lang = "en"
        speech = Speech(self.data, lang)

        # you can also apply audio effects while playing (using SoX)
        # see http://sox.sourceforge.net/sox.html#EFFECTS for full effect documentation
        sox_effects = ("tempo", "1.5")
        return speech.play(sox_effects)
Example #28
0
def say(text=None, lang="en", robot=False):
    import os
    from google_speech import Speech
    if text is None:
        say_fortune()
    elif text == "flipkart":
        say_fk_fortune()
    else:
        speech = Speech(text, lang)
        if not robot:
            sox_effects = ("speed", "1.02", "vol", "0.3")
        else:
            sox_effects = ("speed 0.9 overdrive 10 echo 0.8 0.7 "
                           "6 0.7 echo 0.8 0.7 10 0.7 echo 0.8 0.7 "
                           "12 0.7 echo 0.8 0.88 12 0.7 echo 0.8 "
                           "0.88 30 0.7 echo 0.6 0.6 60 0.7").split(" ")
        speech.play(sox_effects)
        print(text)
Example #29
0
        def inner(*args, **kwargs):
            jk = kwargs.pop('jk', None)
            # before function call:
            if jk:
                text = "LOL! Then why are you asking me to run '" + fun.__name__ + "'? Unbelievable!"
                speech = Speech(text, lang)
                speech.play(None)

            # function call:
            if run_anyway or not jk:
                out = fun(*args, **kwargs)
            else:
                out = None

            # after function call:
            if jk:
                message_idx = randint(0, len(messages.default) - 1)
                text = messages.default[message_idx]
                speech = Speech(text, lang)
                speech.play(None)
            return out
    def handleKeyEvent(self, symbol, modifiers):
        if symbol == pyglet.window.key.BACKSPACE:
            self.currentPage == START_PAGE
            return

        if self.currentPage == START_PAGE:
            if symbol == pyglet.window.key._1:
                self.initPage(MANAGE_WORDBANK_PAGE)
            elif symbol == pyglet.window.key._2:
                self.initPage(START_DICTATION_PAGE)
            elif symbol == pyglet.window.key._3:
                self.initPage(SETTINGS_PAGE)

        elif self.currentPage == MANAGE_WORDBANK_PAGE:
            pass

        elif self.currentPage == START_DICTATION_PAGE:
            if symbol == pyglet.window.key.ENTER:
                self.initPage(IN_DICTATION_PAGE)
            #test only
            if symbol == pyglet.window.key._1:
                self.toggleSelect(self.wordbank.wordlists()[0])
            elif symbol == pyglet.window.key._2:
                self.toggleSelect(self.wordbank.wordlists()[1])

        elif self.currentPage == IN_DICTATION_PAGE:
            if symbol == pyglet.window.key.RIGHT:
                print(self.wordsToDictate[self.dictationIndex])
                self.dictationIndex = (self.dictationIndex + 1) % len(
                    self.wordsToDictate)
                speech = Speech(self.wordsToDictate[self.dictationIndex],
                                LANG_CN_MANDARIN)
                speech.play()
            elif symbol == pyglet.window.key.R:
                speech = Speech(self.wordsToDictate[self.dictationIndex],
                                LANG_CN_MANDARIN)
                speech.play()

        elif currentPage == SETTINGS_PAGE:
            pass