def record_and_test(textbox, button, filename="test_files/test.wav"):
    # Buton on
    button.configure(state="disabled")
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.insert(INSERT, "Recording")
    textbox.tag_add("recording", "1.0", END)
    textbox.configure(state="disabled")

    # Record to test
    record_to_file(filename)

    # Feed into ANN
    testNet = testInit()
    inputArray = extractFeature(filename)
    print(len(inputArray))
    outStr = feedToNetwork(inputArray, testNet)

    # Button of
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.tag_remove("recording", "1.0")
    textbox.insert(INSERT, outStr)
    textbox.tag_add("success", "1.0", END)
    textbox.configure(state="disabled")
    button.configure(state="normal")
def record_and_test(textbox, button, filename="test_files/test.wav"):

    # Disable button and change text
    button.configure(state="disabled")
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.insert(INSERT, "Recording")
    textbox.tag_add("recording", "1.0", END)
    textbox.configure(state="disabled")

    # Record to file
    record_to_file(filename)

    # Feed into ANN
    testNet = testInit()
    inputArray = extractFeature(filename)
    print len(inputArray)
    outStr = feedToNetwork(inputArray,testNet)

    # Change text and re-enable button
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.tag_remove("recording", "1.0")
    textbox.insert(INSERT, outStr)
    textbox.tag_add("success", "1.0", END)
    textbox.configure(state="disabled")
    button.configure(state="normal")
def record_and_train(textbox, button):

    # button on
    button.configure(state="disabled")
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.insert(INSERT, "Recording")
    textbox.tag_add("recording", "1.0", END)
    textbox.configure(state="disabled")

    words = ['down', 'eat', 'sleep', 'up']
    for i in range(len(words)):  # WORD loop
        for j in range(10):  # REPEAT loop
            # record to train
            record_to_file("training_sets/" + words[i] + "-" + str(j + 1) +
                           ".wav")

            print("repeat", words[i])
        if (len(words) != i + 1):
            print("next word", words[i + 1])
        else:
            print("finish")

    # Button of
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.tag_remove("recording", "1.0")
    textbox.tag_add("success", "1.0", END)
    textbox.configure(state="disabled")
    button.configure(state="normal")

    # MFCC calculation and TRAIN
    mfcc_apply()
    print("train start..")
    TRAIN()
Example #4
0
def test_with_recording():
    import wave
    from record import record_to_file, play_sound_file

    test_audio_file = f"{current_dir}/tmp/api_test.wav"
    if not os.path.isfile(test_audio_file):
        record_to_file(test_audio_file, sampling_freq=10000)
    play_sound_file(test_audio_file)
    result = send_to_speech_api(test_audio_file)
    print(result)
Example #5
0
def main():

    import wave
    from record import record_to_file, play_sound_file

    test_audio_file = f"{current_dir}/tmp/api_test.wav"
    if not os.path.isfile(test_audio_file):
        record_to_file(test_audio_file, sampling_freq=16000)
    play_sound_file(test_audio_file)
    result = transcribe_file(f"{current_dir}/tmp/api_test.wav")
    print(result)
Example #6
0
def record_some_words():
    sleep(2)
    speak("Bitte sprechen Sie nach dem Piepston")
    beep = Beep()
    beep.play(1000)

    record_to_file('demo.wav')

    speak("Danke! Sie haben folgende Nachricht aufgenommen:")
    play_from_file('demo.wav')

    speak("... und noch einmal:")
    play_from_file('demo.wav')
Example #7
0
def test_with_live_recording(duration=1, sampling_rate=10000):
    """
    Test the API by recording a digit using the microphone and then preprocessing it, sending the spectrogram and awaiting the result.
    """
    from time import sleep
    from make_spectrograms import make_spectrogram_from_wav_file
    from record import record_to_file, play_sound_file, record, write_to_file

    test_audio_file = f"{current_dir}/tmp/api_test.wav"
    test_img_path = f"{current_dir}/tmp/api_test.png"

    # do a quick countdown before recording.
    for i in reversed(range(4)):
        print(f"\rRecording in {i}", end="\r")
        sleep(1)

    record_to_file(test_audio_file,
                   recording_length_secs=duration,
                   sampling_freq=sampling_rate)
    play_sound_file(test_audio_file)
    result = send_to_speech_api(test_audio_file)
    print(result)
Example #8
0
def record_and_test(textbox, button, filename):

    button.configure(state="disabled")
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.insert(INSERT, "Recording")
    textbox.tag_add("recording", "1.0", END)
    textbox.configure(state="disabled")

    record_to_file(filename)

    testNet = testInit()
    inputArray = extractFeature(filename)
    print len(inputArray)
    outStr = "Detected : " + str(feedToNetwork(inputArray, testNet) + 1)

    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.tag_remove("recording", "1.0")
    textbox.insert(INSERT, outStr)
    textbox.tag_add("success", "1.0", END)
    textbox.configure(state="disabled")
    button.configure(state="normal")
Example #9
0
def record_and_test(textbox, button, filename):

    button.configure(state="disabled")
    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.insert(INSERT, "Recording")
    textbox.tag_add("recording", "1.0", END)
    textbox.configure(state="disabled")

    record_to_file(filename)

    testNet = testInit()
    inputArray = extractFeature(filename)
    print len(inputArray)
    outStr = "Detected : " + str(feedToNetwork(inputArray,testNet)+1)

    textbox.configure(state="normal")
    textbox.delete("1.0", END)
    textbox.tag_remove("recording", "1.0")
    textbox.insert(INSERT, outStr)
    textbox.tag_add("success", "1.0", END)
    textbox.configure(state="disabled")
    button.configure(state="normal")
Example #10
0
 def recordSoundData(self):
     record.record_to_file("/tmp/%s.lyric" % self.hash)
Example #11
0
import playsound as plsnd
import requests as req

HOST = "http://192.168.0.103:3000"

if __name__ == '__main__':
    testNet = testInit()

    num_loop = 0
    filename = "test_files/test.wav"

    while True:
        # Record to file
        num_loop += 1
        print("please speak a word into the microphone", num_loop)
        record_to_file(filename)

        # Feed into ANN
        inputArray = extractFeature(filename)
        res = feedToNetwork(inputArray, testNet)

        if (res == 0):
            # ban can giup gi?
            plsnd.playsound("speak_out_files/bancangiupgi.wav")
            print("Ban can giup gi? ...")

            record_to_file(filename)

            inputArray = extractFeature(filename)
            res = feedToNetwork(inputArray, testNet)
Example #12
0
File: app.py Project: e-cal/VAAD
def run_record(status):
    record_to_file('query.wav')
    status.audio = True
    status.stop_recording()
Example #13
0
## здесь соберем все воедино
import acrcloud_api
import vk_api
import record

# авторизовываемся в вк
api = vk_api.authorization(access_token=vk_api.access_token)

# получаем путь к файлу от алексы...

#но пока стандартный

music_file_path = '/Users//Desktop/Git/icon_hack/demo.mp3'  # запись в файл wave.mp3
record.record_to_file(music_file_path)  # запись с микрофона

# обрабатываем его через acrcloud_api
responce = acrcloud_api.get_responce(config=acrcloud_api.config,
                                     music_file_path=music_file_path,
                                     start_seconds=3)
title, artist = acrcloud_api.parce_responce(responce)

# отправляем шаблонную строку в вк
pattern_string = "Это песня " + title + " исполнителя " + artist + "!"
# еще хз как выбирать юзера, поэтому отправляю себе
#vk_api.send_message(api=api, user_id=62811131, message=pattern_string)
Example #14
0
 def RecordSpeech(self):
     print "please speak a word into the microphone"
     record_to_file(join(dirname(__file__),self.audiofile))
     print "done - result written to audio.wav"
import sys
import record

if __name__ == '__main__':
	record.record_to_file(sys.stdout)
Example #16
0
def exp_evidence(logits):
    return np.exp(np.clip(logits, -10, 10))


def uncertainty_score(logits_output):
    evidence = exp_evidence(logits_output)
    alpha = evidence + 1
    u_score = 10 / np.sum(alpha, axis=1, keepdims=True)  # K = num_classes = 10
    return u_score


while True:
    print("Listening...")
    record_start = time()
    record_to_file("sound/input.wav")
    record_time = time() - record_start

    work_dir = 'sound'
    start_time = time()
    test_x, test_y = data_processing(work_dir)
    load_time = time() - start_time

    # # Testing on loaded model
    start_time = time()
    output = sess.run(output_tensor, feed_dict={model_input: test_x})

    y_pred = predict_label(output)
    uncertainty_y_list = uncertainty_score(output)
    test_time = time() - start_time
    print("Inference time:", infer_time)