Example #1
0
def RecognizeSpeech(AUDIO_FILENAME, num_seconds=5):

    # record audio of specified length in specified audio file
    record_audio(num_seconds, AUDIO_FILENAME)

    # reading audio
    audio = read_audio(AUDIO_FILENAME)

    # defining headers for HTTP request
    headers = {
        'authorization': 'Bearer ' + wit_access_token,
        'Content-Type': 'audio/wav'
    }

    # making an HTTP post request
    resp = requests.post(API_ENDPOINT, headers=headers, data=audio)

    # converting response content to JSON format
    data = json.loads(resp.content)

    # get text from data
    text = data['_text']

    # return the text
    return text
Example #2
0
def RecognizeSpeech(AUDIO_FILENAME, num_seconds):

    # record audio of specified length in specified audio file
    record_audio(num_seconds, AUDIO_FILENAME)

    # reading audio
    audio = read_audio(AUDIO_FILENAME)

    # defining headers for HTTP request
    headers = {'authorization': 'Bearer ' + wit_access_token,
               'Content-Type': 'audio/wav'}

    # making an HTTP post request
    resp = requests.post(API_ENDPOINT, headers = headers,
                         data = audio)
    #print('Http post request=',resp)
    # converting response content to JSON format
    data = json.loads(resp.content)
    #print(data)
    entities = list(data['entities'].keys())
    #print('data dictionary = ',entities)
    # get text from data
    text = data['text']

    print("\nYou said: {}".format(text))
    # return the text
    return entities
def RecognizeSpeechGoogle(AUDIO_FILENAME, num_seconds=5):
    recogniser = sr.Recognizer()
    record_audio(num_seconds,AUDIO_FILENAME)
    audio_file = sr.AudioFile(AUDIO_FILENAME)
    with audio_file as source:
        recogniser.adjust_for_ambient_noise(source)
        audio = recogniser.record(source)
    try:
        text = recogniser.recognize_google(audio)
        return text
    except:
        return ""
Example #4
0
def RecognizeSpeech(AUDIO_FILENAME, num_seconds = 5):
    
    record_audio(num_seconds, AUDIO_FILENAME)
    audio = read_audio(AUDIO_FILENAME)
    headers = {'authorization': 'Bearer ' + wit_access_token,
               'Content-Type': 'audio/wav'}
    resp = requests.post(API_ENDPOINT, headers = headers,
                         data = audio)
    # print(resp.content)
    # input()
    data = json.loads(resp.content)
    text = data['_text']
    return text
def start_record_audio():
    # record audio and save in memory (BytesIO)
    temp_file = io.BytesIO()
    audio_bytes = record_audio(config, temp_file)

    # reading audio
    audio = read_audio(audio_bytes)

    thread_text_from_audio = threading.Thread(target=get_text_from_audio,
                                              args={audio: audio})
    thread_text_from_audio.start()
Example #6
0
def RecognizeSpeech(AUDIO_FILENAME, num_seconds = 5):

    # record audio of specified length in specified audio file
    record_audio(num_seconds, AUDIO_FILENAME)

    # reading audio
    audio = read_audio(AUDIO_FILENAME)

    # defining headers for HTTP request
    headers = {'authorization': 'Bearer ' + wit_access_token,
               'Content-Type': 'audio/wav'}

    # making an HTTP post request
    resp = requests.post(API_ENDPOINT, headers = headers,
                         data = audio)

    # converting response content to JSON format
    data = json.loads(resp.content)
    # get text from data
    try:
        text = data['_text']
        print("\nYou said: {}".format(text))
    except:
        text = ""
        print("\nYou said: {}".format(text))

    text = re.sub("srf 1","srf1",text.lower())
    text = re.sub("sf1","srf1",text.lower())
    text = re.sub("sr1","srf1",text.lower())
    text = re.sub("srf 3","srf3",text.lower())
    text = re.sub("sf3","srf3",text.lower())
    text = re.sub("sr3","srf3",text.lower())
    text = re.sub("ruhr","ruhe",text.lower())
    text = re.sub("einruhr","ruhe",text.lower())
    text = re.sub("hansgrohe","ruhe",text.lower())
    text = re.sub("heimpsiel","heidi spiel",text)
    text = re.sub("hayden spiel","heidi spiel",text)
    text = re.sub("highspeed","heidi spiel",text)
    text = re.sub("handyspiel","heidi spiel",text)

    #understand what i need
    resp = requests.get('https://api.wit.ai/message?v=01.03.2018&q=(%s)' % text, headers = headers)

    data = json.loads(resp.content)
    print(resp.content)

    try:
        sender = data["entities"]['spiel'][0]["value"]
        print("\nI got entity : {}".format(sender))
    except:
        if text != "":
            os.system("mplayer nocomprendo1.wav")
        sender = ""
    if sender == "srf1" :
        kill_mplayer()
        os.system("mplayer http://stream.srg-ssr.ch/m/drs1/aacp_96  </dev/null >/dev/null 2>&1 &")
    if sender == "srf3":
        kill_mplayer()
        os.system("mplayer http://stream.srg-ssr.ch/m/drs3/aacp_96  </dev/null >/dev/null 2>&1 &")
    if sender == "espresso":
        kill_mplayer()
        os.system("mplayer $(youtube-dl -g http://tp.srgssr.ch/p/srf/inline\?urn\=urn:srf:audio:b88af97b-8d44-4b29-9b81-28e3e9be8657) </dev/null >/dev/null 2>&1 &")
    if sender == "ruhe":
        kill_mplayer()
        os.system("mplayer ja1.wav")