Esempio n. 1
0
def speech_rec_for_linux():
    import espeak
    espeak.init()
    speaker = espeak.Espeak()
    # import pyttsx3
    # speaker = pyttsx3.init()

    r = sr.Recognizer()
    text = ""
    count = 0
    medicines = {}

    with sr.Microphone() as source:
        while (True):
            medicine_dict = {}
            count += 1

            print("Medicine-" + str(count) + " Information")

            print("Adjusting noise ")
            r.adjust_for_ambient_noise(source, duration=1)

            print("Medicine Name:")
            speaker.say("Medicine name")
            # speaker.rate = 300

            recorded_audio = r.listen(source, timeout=6)
            print("Done")

            try:
                text = r.recognize_google(recorded_audio, language="en-US")
                if 'exit' in str(text).lower():
                    print("Thanks for using our service!")
                    break

                medicine_dict["Medicine Name"] = str(text)
                print("Decoded Text : {}".format(text))

            except Exception as e:
                print(e)

            print("Adjusting noise ")
            r.adjust_for_ambient_noise(source, duration=1)

            print("Medicine Instruction:")
            speaker.say("Medicine Instruction")

            recorded_audio = r.listen(source, timeout=6)
            print("Done")

            try:
                text = r.recognize_google(recorded_audio, language="en-US")
                medicine_dict["Instruction"] = str(text)
                print("Decoded Text : {}".format(text))

            except Exception as e:
                print(e)

            medicines["Medicine No. " + str(count)] = medicine_dict

    return medicines
Esempio n. 2
0
    GPIO.output(pin1, GPIO.LOW)
    GPIO.output(pin2, GPIO.LOW)


def forward(pin1, pin2):
    GPIO.output(pin1, GPIO.HIGH)
    GPIO.output(pin2, GPIO.LOW)


def backward(pin1, pin2):
    forward(pin2, pin1)


while True:
    ## Initializing ##
    espeak.init()
    speaker = espeak.Espeak()
    print("Finding ps3 controller...")
    devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
    ps3dev = None
    for device in devices:
        print(device.path, device.name, device.phys)
        if device.name == 'Sony PLAYSTATION(R)3 Controller':
            ps3dev = device.fn
            print(ps3dev)
        else:
            print("Other device")
    if ps3dev is None:
        sleep(2)
        continue
 def __init__(self):
     espeak.init()
     self.speaker = espeak.Espeak()
Esempio n. 4
0
        if newtext is not None:
            self.stop()
            self.text = newtext
        self.say(self.text,
                 self.position,
                 ssml=self.ssml,
                 phonemes=self.phonemes,
                 endpause=self.endpause)

    def __setattr__(self, key, value):
        if (key in espeak.const["parameter"] and self.param_change_restart and\
           self.playing()):
            self.pause()
            espeak.Espeak.__setattr__(self, key, value)
            self.play()
        else:
            espeak.Espeak.__setattr__(self, key, value)

    def saysentence(self, index=-1):
        text = self.text[self.sentences[index - 1] - 1:self.sentences[index] -
                         1]
        espinner = Espeaker(text)
        espinner.play()
        return espinner


if __name__ == '__main__':
    espeak.init(playback=False)
    file_espeak = FileEspeak(open("test.wav", "wb"))
    file_espeak.say("Hello world")