Exemplo n.º 1
0
    def enroll_new_profile(self):
        subscription_key = 'ccc2411ed1bb496fbc3aaf42540e81ac'

        enroll_file = './data/enroll_tmp.wav'
        try:
            os.remove(enroll_file)
        except OSError:
            pass
        # enroll_name = self.Sending_data.get('1.0', 'end')[:-1]
        enroll_name = 'temp~'
        locale = 'en-us'
        # locale = enroll_name
        # 1, record audio to ./data/enroll_tmp.wav
        duration = 10  # seconds
        myrecording = sd.rec(duration * fs, samplerate=fs,
                             channels=1)  # array(fs)
        print("正在采集声纹信息,请说话...")
        sd.wait()
        sf.write(enroll_file, myrecording, fs)
        print("采集完毕,正在加入数据库...")

        # 2, create_profile
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        creation_response = helper.create_profile(locale)
        profile_id = creation_response.get_profile_id()
        print('profile_id:', profile_id)

        # 3, Enroll user profiles with provided wav files
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        enrollment_response = helper.enroll_profile(profile_id, enroll_file,
                                                    "true")
        print('status:', enrollment_response.get_enrollment_status())
        if enrollment_response.get_enrollment_status() == 'Enrolled':
            self.profile_ids.append(profile_id)
            self.profile_nms.append(enroll_name)
            print('enroll ok:', enroll_name)
        else:
            print('enroll fail:', enroll_name)

        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        profiles = helper.get_all_profiles()
        print(
            'Profile ID, Locale, Enrollment Speech Time, Remaining Enrollment Speech Time,'
            ' Created Date Time, Last Action Date Time, Enrollment Status')
        for profile in profiles:
            name = self.profile_nms[self.profile_ids.index(
                profile.get_profile_id())]
            print('{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}'.format(
                profile.get_profile_id(), profile.get_locale(),
                profile.get_enrollment_speech_time(),
                profile.get_remaining_enrollment_time(),
                profile.get_created_date_time(),
                profile.get_last_action_date_time(),
                profile.get_enrollment_status(), name))
Exemplo n.º 2
0
def print_all_profiles(subscription_key):
    """Print all the profiles for the given subscription key.

    Arguments:
    subscription_key -- the subscription key string
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    profiles = helper.get_all_profiles()

    print('Profile ID, Locale, Enrollment Speech Time, Remaining Enrollment Speech Time,'
          ' Created Date Time, Last Action Date Time, Enrollment Status')
    profile_IDs = []
    for profile in profiles:
        profile_IDs.append(profile.get_profile_id())
        print('{0}, {1}, {2}, {3}, {4}, {5}, {6}'.format(
            profile.get_profile_id(),
            profile.get_locale(),
            profile.get_enrollment_speech_time(),
            profile.get_remaining_enrollment_time(),
            profile.get_created_date_time(),
            profile.get_last_action_date_time(),
            profile.get_enrollment_status()))
    return profile_IDs
Exemplo n.º 3
0
    def buttonClick(self, file):

        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        identification_response = helper.identify_file(file, ident_profile_IDs)
        if identification_response.get_identified_profile_id(
        ) == '00000000-0000-0000-0000-000000000000':
            messagebox.showinfo(title="Profile not found!",
                                message="There was no match!")
        else:
            profile_index = ident_profile_IDs.index(
                identification_response.get_identified_profile_id())

        if identification_response.get_confidence() != "High":
            messagebox.showinfo(title="Profile not found!",
                                message="There was no match!")

        elif identification_response.get_identified_profile_id(
        ) == ident_profile_IDs[profile_index]:
            messagebox.showinfo(
                title="Profile identified",
                message="The sample voice is identified as that of " +
                labels[profile_index] + "!\nConfidence = " +
                identification_response.get_confidence())
def reset_identification_enrollments():
    """Reset enrollments of a given profile from the server

    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to reset
    """

    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    selected_profile = input('Please select the profile you wish to reset: ')

    if selected_profile == '1':
        helper.reset_enrollments('842c6a50-dbc3-4aab-8ccc-6190b971b947')
        print('the profile "Goran" has been successfully reset')

    elif selected_profile == '2':
        helper.reset_enrollments('970d80f8-1737-422b-be2d-c49cf140a95a')
        print('The profile "Meho" has been successfully reset')

    elif selected_profile == '3':
        helper.reset_enrollments('c6101e08-45e8-4e3a-90ee-3aa795ae355e')
        print('The profile "Filip" has been successfully reset')

    elif selected_profile == '4':
        helper.reset_enrollments('dcfef31e-3bb8-44bd-b7a8-c7bd78166e39')
        print('the profile "Viktorija" has been successfully reset')

    elif selected_profile == '5':
        helper.reset_enrollments('1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9')
        print('The profile "Dominik" has been successfully reset')

    else:
        print('There is no such profile\n')
def delete_identification_profile():
    """ Deletes a profile from the server

    Arguments:
    profile_id -- the profile ID string of user to delete
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    print('Please select the profile you wish to delete:\n')

    selected_profile = input('Your choice: ')

    if selected_profile == '1':
        helper.delete_profile('842c6a50-dbc3-4aab-8ccc-6190b971b947')
        print('the profile "Goran" has been deleted')

    if selected_profile == '2':
        helper.delete_profile('970d80f8-1737-422b-be2d-c49cf140a95a')
        print('The profile "Meho" has been deleted')

    if selected_profile == '3':
        helper.delete_profile('c6101e08-45e8-4e3a-90ee-3aa795ae355e')
        print('The profile "Filip" has been deleted')

    if selected_profile == '4':
        helper.delete_profile('dcfef31e-3bb8-44bd-b7a8-c7bd78166e39')
        print('The profile "Viktorija" has been deleted')

    if selected_profile == '5':
        helper.delete_profile('1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9')
        print('The profile "Dominik" has been deleted')

    else:
        print('There is no such profile\n')
def delete_profile():
    """ Deletes a profile from the server

    Arguments:
    profile_id -- the profile ID string of user to delete
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    print('Please select the profile you wish to delete:\n')

    selected_profile = input('Your choice: ')

    if selected_profile == '1':
        helper.delete_profile('842c6a50-dbc3-4aab-8ccc-6190b971b947')
        print('the profile "Goran" has been deleted')

    if selected_profile == '2':
        helper.delete_profile('970d80f8-1737-422b-be2d-c49cf140a95a')
        print('The profile "Meho" has been deleted')

    if selected_profile == '3':
        helper.delete_profile('c6101e08-45e8-4e3a-90ee-3aa795ae355e')
        print('The profile "Filip" has been deleted')

    if selected_profile == '4':
        # helper.delete_profile('c6101e08-45e8-4e3a-90ee-3aa795ae355e')
        print('There is no such profile')

    if selected_profile == '5':
        helper.delete_profile('f4d974e4-33f2-4ebe-9865-646c66b3f62f')
        print('There is no such profile')
Exemplo n.º 7
0
def create_profile(subscription_key, locale):
    """Creates a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    locale -- the locale string
    """
    getAudio()
    
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    creation_response = helper.create_profile(locale)

    print('Profile ID = {0}'.format(creation_response.get_profile_id()))
    
    profileid = creation.response.get_profile_id()

    enrollment_response = helper.enroll_profile(
        profileid,
        "result.wav",
        force_short_audio.lower() == "true")
    
    print('Total Enrollment Speech Time = {0}'.format(enrollment_response.get_total_speech_time()))
    print('Remaining Enrollment Time = {0}'.format(enrollment_response.get_remaining_speech_time()))
    print('Speech Time = {0}'.format(enrollment_response.get_speech_time()))
    print('Enrollment Status = {0}'.format(enrollment_response.get_enrollment_status()))
Exemplo n.º 8
0
    def post(self):
        print('---------------enter post...')
        try:
            audio = RequestHandler.get_body_argument(self, name='audio')  # '1,1,1,...,11,2'
            audio_lst_str = audio.split(',')  # [str*32000]
            audio_lst_int = [float(i) for i in audio_lst_str]
            audio_array = np.asarray(audio_lst_int)
            audio_array = np.expand_dims(audio_array, axis=1)
            try:
                os.remove(filePath)
            except OSError:
                pass
            sf.write(filePath, audio_array, fs)
            helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper('ccc2411ed1bb496fbc3aaf42540e81ac')
            identification_response = helper.identify_file(filePath, profile_ids, 'true')
            id = identification_response.get_identified_profile_id()

            name = profile_nms[profile_ids.index(id)] if id in profile_ids else 'stranger'
            print('result:', name)
            print('c onfidence:', identification_response.get_confidence())
            self.write(name + '\n')

        except Exception as e:
            print('receieve post but something error:' + str(e))
            self.write('error' + '\n')
            pass
Exemplo n.º 9
0
def create_profile(subscription_key, locale):
   helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

   creation_response = helper.create_profile(locale)
   id1=creation_response.get_profile_id()
   print('Profile ID = {0}'.format(id1))
   return(id1)
Exemplo n.º 10
0
def delete_profile(subscription_key, profile_id):
    """ Deletes a profile from the server
		
		Arguments:
		profile_id -- the profile ID string of user to delete
		"""
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)
    helper.delete_profile(profile_id)

    print('Profile {0} has been successfully deleted.'.format(profile_id))
Exemplo n.º 11
0
    def buttonClick(self, selection):
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        profile_index = labels.index(selection)

        if selection == labels[profile_index]:
            helper.reset_enrollments(ident_profile_IDs[profile_index])
            messagebox.showinfo(title="Success",
                                message="Profile " + selection +
                                " successfully reset!")
def create_profile(subscription_key, locale):
    """Creates a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    locale -- the locale string
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    creation_response = helper.create_profile(locale)
    return creation_response.get_profile_id()
def create_identification_profile():
    """Creates a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    locale -- the locale string
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    creation_response = helper.create_profile('en-us')

    print('Profile ID = {0}'.format(creation_response.get_profile_id()))
def enroll_identification_profile():
    """Enrolls a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to enroll
    file_path -- the path of the file to use for enrollment
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    enroll_selected_profile = input('Please select the profile you wish to enroll: ')

    if enroll_selected_profile == '1':
        enrollment_response = helper.enroll_profile(
            '842c6a50-dbc3-4aab-8ccc-6190b971b947',
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Goran_pass.wav',
            'true')

    elif enroll_selected_profile == '2':
        enrollment_response = helper.enroll_profile(
            '970d80f8-1737-422b-be2d-c49cf140a95a',
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Meho_pass.wav',
            'true')

    elif enroll_selected_profile == '3':
        enrollment_response = helper.enroll_profile(
            'c6101e08-45e8-4e3a-90ee-3aa795ae355e',
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Filip_pass.wav',
            'true')

    elif enroll_selected_profile == '4':
        enrollment_response = helper.enroll_profile(
            'dcfef31e-3bb8-44bd-b7a8-c7bd78166e39',
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Viktorija_pass.wav',
            'true')

    elif enroll_selected_profile == '5':
        enrollment_response = helper.enroll_profile(
            '1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9',
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Dominik_pass.wav',
            'true')

    else:
        print('There is no such profile\n')

    print('Total Enrollment Speech Time = {0}'.format(enrollment_response.get_total_speech_time()))
    print('Remaining Enrollment Time = {0}'.format(enrollment_response.get_remaining_speech_time()))
    print('Speech Time = {0}'.format(enrollment_response.get_speech_time()))
    print('Enrollment Status = {0}'.format(enrollment_response.get_enrollment_status()))
Exemplo n.º 15
0
def identify_file(subscription_key, file_path, profile_ids):
    """Identify an audio file on the server.

    Arguments:
    subscription_key -- the subscription key string
    file_path -- the audio file path for identification
    profile_ids -- an array of test profile IDs strings
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)
    identification_response = helper.identify_file(file_path, profile_ids)
    print('Identified Speaker = {0}'.format(
        identification_response.get_identified_profile_id()))
    print('Confidence = {0}'.format(identification_response.get_confidence()))
def reset_enrollments(subscription_key, profile_id):
    """Reset enrollments of a given profile from the server
    
    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to reset
    """
    
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)
        
    helper.reset_enrollments(profile_id)
    
    print('Profile {0} has been successfully reset.'.format(profile_id))
Exemplo n.º 17
0
def get_profile(subscription_key, profile_id):
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)
    
    profile = helper.get_profile(profile_id)
    
    print('Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
        profile._profile_id,
        profile._locale,
        profile._enrollment_speech_time,
        profile._remaining_enrollment_time,
        profile._created_date_time,
        profile._last_action_date_time,
        profile._enrollment_status))
Exemplo n.º 18
0
    def buttonClick(self, selection, path):
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        profile_index = labels.index(selection)

        if selection == labels[profile_index]:
            enrollment_response = helper.enroll_profile(
                ident_profile_IDs[profile_index], path)
            messagebox.showinfo(
                title="Success",
                message="Profile " + selection +
                " successfully enrolled!\n\nTotal enrollment speech time: " +
                str(enrollment_response.get_total_speech_time()) +
                "\nRemaining enrollment time: " +
                str(enrollment_response.get_remaining_speech_time()) +
                "\nEnrollment status: " +
                str(enrollment_response.get_enrollment_status()))
Exemplo n.º 19
0
def get_profile(subscription_key, profile_id):
    """Get a speaker's profile with given profile ID
    
    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to resets
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    profile = helper.get_profile(profile_id)

    print(
        'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'
        .format(profile._profile_id, profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time, profile._created_date_time,
                profile._last_action_date_time, profile._enrollment_status))
def identify_file(subscription_key, file_path, force_short_audio, profile_ids):
    """Identify an audio file on the server.

    Arguments:
    subscription_key -- the subscription key string
    file_path -- the audio file path for identification
    profile_ids -- an array of test profile IDs strings
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    identification_response = helper.identify_file(
        file_path, profile_ids,
        force_short_audio.lower() == "true")

    print('Identified Speaker = {0}'.format(identification_response.get_identified_profile_id()))
    print('Confidence = {0}'.format(identification_response.get_confidence()))
def enroll_profile(subscription_key, profile_id, file_path):
    """Enrolls a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to enroll
    file_path -- the path of the file to use for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    enrollment_response = helper.enroll_profile(profile_id, file_path)

    print('Total Enrollment Speech Time = {0}'.format(
        enrollment_response.get_total_speech_time()))
    print('Remaining Enrollment Time = {0}'.format(
        enrollment_response.get_remaining_speech_time()))
    print('Speech Time = {0}'.format(enrollment_response.get_speech_time()))
    print('Enrollment Status = {0}'.format(
        enrollment_response.get_enrollment_status()))
Exemplo n.º 22
0
def identify_file(subscription_key, file_path, force_short_audio, profile_ids):
    """Identify an audio file on the server.

    Arguments:
    subscription_key -- the subscription key string
    file_path -- the audio file path for identification
    profile_ids -- an array of test profile IDs strings
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    identification_response = helper.identify_file(
        file_path, profile_ids,
        force_short_audio.lower() == "true")
    #print(profile_ids[0])
    #print(identification_response.get_identified_profile_id())

    if (profile_ids[0] == identification_response.get_identified_profile_id()):
        print("true")
    else:
        print("false")

    #print('{0}'.format(identification_response.get_identified_profile_id()))
    print('{0}'.format(identification_response.get_confidence()))

    r = sr.Recognizer()

    audio = "uploads\identify.wav"

    with sr.AudioFile(audio) as source:
        #print('Say Something!')
        audio = r.record(source)
        #print('Done!')

    try:
        text = r.recognize_google(audio)
        print(text)

    except Exception as e:
        print(e)
Exemplo n.º 23
0
    def print_all(self):
        subscription_key = 'ccc2411ed1bb496fbc3aaf42540e81ac'
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        profiles = helper.get_all_profiles()
        print('===============================================')
        print(
            'Profile ID, Locale, Enrollment Speech Time, Remaining Enrollment Speech Time,'
            ' Created Date Time, Last Action Date Time, Enrollment Status')
        for profile in profiles:
            name = self.profile_nms[self.profile_ids.index(
                profile.get_profile_id())] if profile.get_profile_id(
                ) in self.profile_ids else 'stranger'
            print('{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}'.format(
                profile.get_profile_id(), profile.get_locale(),
                profile.get_enrollment_speech_time(),
                profile.get_remaining_enrollment_time(),
                profile.get_created_date_time(),
                profile.get_last_action_date_time(),
                profile.get_enrollment_status(), name))
Exemplo n.º 24
0
def enroll_profile(subscription_key, profile_id, file_path, force_short_audio):
    """Enrolls a profile on the server.

    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to enroll
    file_path -- the path of the file to use for enrollment
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        subscription_key)

    enrollment_response = helper.enroll_profile(profile_id, file_path,
                                                force_short_audio == True)

    print('Total Enrollment Speech Time = {0}'.format(
        enrollment_response.get_total_speech_time()))
    print('Remaining Enrollment Time = {0}'.format(
        enrollment_response.get_remaining_speech_time()))
    print('Speech Time = {0}'.format(enrollment_response.get_speech_time()))
    print('Enrollment Status = {0}'.format(
        enrollment_response.get_enrollment_status()))
Exemplo n.º 25
0
def identify_file(subscription_key, file_path, force_short_audio, profile_ids):
    """Identify an audio file on the server.

    Arguments:
    subscription_key -- the subscription key string
    file_path -- the audio file path for identification
    profile_ids -- an array of test profile IDs strings
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    try:
        helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        identification_response = helper.identify_file(
            file_path, profile_ids, force_short_audio == "true")
        idd = identification_response.get_identified_profile_id()
        print('Identified Speaker = {0}'.format(idd))
        print('Confidence = {0}'.format(
            identification_response.get_confidence()))
        return (idd)
    except AttributeError as error:
        # Output expected AttributeErrors.
        return (000000000 - 0000 - 0000 - 0000 - 0000000000)
Exemplo n.º 26
0
    def LoadTable(self):
        helper_ident = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
            subscription_key)

        ident_profiles = helper_ident.get_all_profiles()

        for profile in ident_profiles:

            if profile.get_profile_id() == ident_profile_IDs[0]:
                profile_name = labels[0]
            elif profile.get_profile_id() == ident_profile_IDs[1]:
                profile_name = labels[1]
            elif profile.get_profile_id() == ident_profile_IDs[2]:
                profile_name = labels[2]
            elif profile.get_profile_id() == ident_profile_IDs[3]:
                profile_name = labels[3]
            elif profile.get_profile_id() == ident_profile_IDs[4]:
                profile_name = labels[4]
            elif profile.get_profile_id() == ident_profile_IDs[5]:
                profile_name = labels[5]
            elif profile.get_profile_id() == ident_profile_IDs[6]:
                profile_name = labels[6]
            elif profile.get_profile_id() == ident_profile_IDs[7]:
                profile_name = labels[7]
            elif profile.get_profile_id() == ident_profile_IDs[8]:
                profile_name = labels[8]
            elif profile.get_profile_id() == ident_profile_IDs[9]:
                profile_name = labels[9]

            self.treeview_ident.insert(
                '',
                'end',
                values=(profile.get_profile_id(), profile_name,
                        profile.get_enrollment_speech_time(),
                        profile.get_remaining_enrollment_time(),
                        profile.get_created_date_time(),
                        profile.get_enrollment_status()))
Exemplo n.º 27
0
    # 2,摘要提取------------------------------------
    payload = {'article': article_cn}
    # print('开始摘要预测...')
    title_cn = requests.get('http://35.229.131.169:8008', params=payload)
    if 'unk' in title_cn.text:
        print('摘要预测结果:', title_cn.text.rstrip().replace('<unk>', '') + '*')
        # print('摘要预测耗时:', time.time() - t0, 's')
    if 'UNK' in title_cn.text:
        print('摘要预测结果:', title_cn.text.rstrip().replace('<UNK>', '') + '*')
        # print('摘要预测耗时:', time.time() - t0, 's')
    else:
        print('摘要预测结果:', title_cn.text.rstrip())
        # print('摘要预测耗时:', time.time() - t0, 's')

    # 3,声纹识别------------------------------------
    profile_ids = [
        'aabd9804-3c66-46d1-b8d3-4598b8aca4d8',
        '7874fb49-1c07-493c-b948-a496d6b1d1a9'
    ]
    profile_nms = ['kai', 'kun']

    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        'ccc2411ed1bb496fbc3aaf42540e81ac')
    identification_response = helper.identify_file(filePath, profile_ids,
                                                   'true')
    id = identification_response.get_identified_profile_id()
    name = profile_nms[profile_ids.index(
        id)] if id in profile_ids else '此人不在数据库,需先手动注册'
    print('声纹鉴定结果:', name)
    print('鉴定confidence:', identification_response.get_confidence())
def get_identification_profile():
    """Get a speaker's profile with given profile ID

    Arguments:
    subscription_key -- the subscription key string
    profile_id -- the profile ID of the profile to resets
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    chosen_profile = input('Please select the profile you wish to see: ')

    if chosen_profile == '1':
        profile = helper.get_profile('842c6a50-dbc3-4aab-8ccc-6190b971b947')
        print(
            'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
                profile._profile_id,
                profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time,
                profile._created_date_time,
                profile._last_action_date_time,
                profile._enrollment_status))

    elif chosen_profile == '2':
        profile = helper.get_profile('970d80f8-1737-422b-be2d-c49cf140a95a')
        print(
            'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
                profile._profile_id,
                profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time,
                profile._created_date_time,
                profile._last_action_date_time,
                profile._enrollment_status))

    elif chosen_profile == '3':
        profile = helper.get_profile('c6101e08-45e8-4e3a-90ee-3aa795ae355e')
        print(
            'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
                profile._profile_id,
                profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time,
                profile._created_date_time,
                profile._last_action_date_time,
                profile._enrollment_status))

    elif chosen_profile == '4':
        profile = helper.get_profile('dcfef31e-3bb8-44bd-b7a8-c7bd78166e39')
        print(
            'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
                profile._profile_id,
                profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time,
                profile._created_date_time,
                profile._last_action_date_time,
                profile._enrollment_status))

    elif chosen_profile == '5':
        profile = helper.get_profile('1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9')
        print(
            'Profile ID = {0}\nLocale = {1}\nEnrollments Speech Time = {2}\nRemaining Enrollment Time = {3}\nCreated = {4}\nLast Action = {5}\nEnrollment Status = {6}\n'.format(
                profile._profile_id,
                profile._locale,
                profile._enrollment_speech_time,
                profile._remaining_enrollment_time,
                profile._created_date_time,
                profile._last_action_date_time,
                profile._enrollment_status))

    else:
        print('There is no such profile\n')
def identify_file():
    """Identify an audio file on the server.

    Arguments:
    subscription_key -- the subscription key string
    file_path -- the audio file path for identification
    profile_ids -- an array of test profile IDs strings
    force_short_audio -- waive the recommended minimum audio limit needed for enrollment
    """
    helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
        '359a42dd1486427daf6141db26af54c6')

    identify_selected_file = input('Please enter the name of the desired sample to identify: ')

    profile_IDs = ['842c6a50-dbc3-4aab-8ccc-6190b971b947',
                   '970d80f8-1737-422b-be2d-c49cf140a95a',
                   'c6101e08-45e8-4e3a-90ee-3aa795ae355e',
                   'dcfef31e-3bb8-44bd-b7a8-c7bd78166e39',
                   '1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9']

    if identify_selected_file == 'Goran_pass':

        identification_response = helper.identify_file(
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Goran_pass.wav',
            profile_IDs,
            'true')

        if identification_response.get_identified_profile_id() == '842c6a50-dbc3-4aab-8ccc-6190b971b947':
            print('The sample voice is identified as that of Goran Horvat!')

    elif identify_selected_file == 'Meho_pass':
        identification_response = helper.identify_file(
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Meho_pass.wav',
            profile_IDs,
            'true')

        if identification_response.get_identified_profile_id() == '970d80f8-1737-422b-be2d-c49cf140a95a':
            print('The sample voice is identified as that of Zlatko Mehanović!')

    elif identify_selected_file == 'Filip_pass':
        identification_response = helper.identify_file(
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Filip_pass.wav',
            profile_IDs,
            'true')

        if identification_response.get_identified_profile_id() == 'c6101e08-45e8-4e3a-90ee-3aa795ae355e':
            print('The sample voice is identified as that of Filip Crnko!')

    elif identify_selected_file == 'Viktorija_pass':
        identification_response = helper.identify_file(
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Viktorija_pass.wav',
            profile_IDs,
            'true')

        if identification_response.get_identified_profile_id() == 'dcfef31e-3bb8-44bd-b7a8-c7bd78166e39':
            print('The sample voice is identified as that of Viktorija Sabo!')

    elif identify_selected_file == 'Dominik_pass':
        identification_response = helper.identify_file(
            'C:/Users/ghorv/Desktop/Zavrsni/PrepoznavanjeGlasa/Testing/Dominik_pass.wav',
            profile_IDs,
            'true')

        if identification_response.get_identified_profile_id() == '1ac67c64-ca2b-4ce2-99a7-6d0dc2c086e9':
            print('The sample voice is identified as that of Dominik Smiljanić!')

    else:
        print('There is no such file\n')

    print('Confidence = {0}'.format(identification_response.get_confidence()))
Exemplo n.º 30
0
    def start_stop_record(self):
        if self.rec_status == 'start':
            try:
                os.remove(filePath)
            except OSError:
                pass
            # start record
            self.rec_status = 'recording'
            self.Sending_Button['text'] = 'recording'

            myrecording = sd.rec(duration * fs, samplerate=fs,
                                 channels=1)  # array(fs)
            print("Recording Audio")
            sd.wait()
            sf.write(filePath, myrecording, fs)

            # def rec_audio():
            #     q = queue.Queue()
            #     def callback(indata, frames, time, status):
            #         """This is called (from a separate thread) for each audio block."""
            #         if status:
            #             print(status, file=sys.stderr)
            #         q.put(indata.copy())
            #
            #     # Make sure the file is opened before recording anything:
            #     with sf.SoundFile(filePath, mode='x', samplerate=fs, channels=1) as file:
            #         with sd.InputStream(samplerate=fs, channels=1, callback=callback):
            #             print('请开始讲话,Ctrl+C结束说话...')
            #             while self.rec_status == 'recording':
            #                 print('recording...')
            #                 file.write(q.get())
            #
            # p = multiprocessing.Process(target=rec_audio)
            # p.start()

            # elif self.rec_status == 'recording':
            # end record
            self.rec_status = 'start'
            self.Sending_Button['text'] = '启动'

            print('\n录制结束: ' + repr(filePath) + ',正在进行语音识别...')
            t0 = time.time()

            # 1.1, 首选讯飞语音识别------------------------------------
            f = open(filePath, 'rb')
            file_content = f.read()
            base64_audio = base64.b64encode(file_content)
            body = urllib.parse.urlencode({
                'audio': base64_audio
            }).encode("utf-8")

            url = 'http://api.xfyun.cn/v1/service/v1/iat'
            api_key = 'e3462997d9c9e0ab0bdb02929ba1756a'
            param = {"engine_type": "sms16k", "aue": "raw"}
            x_appid = '5b9f8564'
            x_param = base64.b64encode(
                bytes(json.dumps(param).replace(' ', ''), "utf-8"))
            x_time = int(int(round(time.time() * 1000)) / 1000)

            a = api_key + str(x_time) + x_param.decode('utf-8')
            b = a.encode('utf-8')
            x_checksum = hashlib.md5(b)
            x_checksum = x_checksum.hexdigest()
            x_header = {
                'X-Appid': x_appid,
                'X-CurTime': x_time,
                'X-Param': x_param,
                'X-CheckSum': x_checksum
            }
            req = urllib.request.Request(url, body, x_header)
            result = urllib.request.urlopen(req)
            print('result_0:', type(result), result)
            result = result.read().decode("utf-8")
            result_dict = ast.literal_eval(result)
            print('result_dict:', type(result_dict), result_dict)
            # result = re.findall(u'[\u4e00-\u9fff]+', result)
            # article_cn = ','.join(result)
            article_cn = result_dict['data']
            print('article_cn:', type(article_cn), article_cn)

            # 1.2, 备用语音识别------------------------------------
            if article_cn == '':
                print('connect xunfei error, change to baidu')
                APP_ID = '14130716'
                API_KEY = '39xGD77Aaq3kTYlefYq8u61X'
                SECRET_KEY = 'AUluhww4RhuLbZXZf66OANyc0OkuiDZz'
                client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

                def get_file_content(filePath):
                    with open(filePath, 'rb') as fp:
                        return fp.read()

                result = client.asr(get_file_content(filePath), 'wav', 16000, {
                    'dev_pid': 1536,
                })
                print('result0:', result)
                article_cn = result['result'][0] if 'result' in result.keys(
                ) else 'connect baidu error'
                print('Recognition result:', article_cn)

            print('语音识别结果:', article_cn)
            # print('语音识别耗时:', time.time() - t0, 's')

            # 2,摘要提取------------------------------------
            payload = {'article': article_cn}
            # print('开始摘要预测...')
            title_cn = requests.get('http://35.229.131.169:8008',
                                    params=payload)
            # title_cn = requests.get('http://127.0.0.1:8008', params=payload)
            print(
                '摘要预测结果:',
                title_cn.text.rstrip().replace('<unk>',
                                               '').replace('<UNK>', ''))

            # 3,声纹识别------------------------------------
            # print('current self.profile_ids:', self.profile_ids)

            helper = IdentificationServiceHttpClientHelper.IdentificationServiceHttpClientHelper(
                'ccc2411ed1bb496fbc3aaf42540e81ac')
            identification_response = helper.identify_file(
                filePath, self.profile_ids, 'true')
            id = identification_response.get_identified_profile_id()
            # print('current profile_id:', id)
            name = self.profile_nms[self.profile_ids.index(
                id)] if id in self.profile_ids else 'stranger'
            print('声纹鉴定结果:', name)
            print('鉴定confidence:', identification_response.get_confidence())

            one_title = name + ': ' + title_cn.text.rstrip().replace(
                '<unk>', '').replace('<UNK>', '') + '\n'
            # self.history.insert("end", one_title)

            start = self.history.index('end') + "-1l"
            self.history.insert(
                "end",
                str(datetime.datetime.now()).split('.')[0] + '\n')
            self.history.insert("end", one_title)
            self.history.insert("end", '\n')
            end = self.history.index('end') + "-1l"
            self.history.tag_add("SENDBYME", start, end)
            self.history.tag_config("SENDBYME", foreground='Blue')

            start = self.history_article.index('end') + "-1l"
            self.history_article.insert(
                "end",
                str(datetime.datetime.now()).split('.')[0] + '\n')
            self.history_article.insert("end", name + ': ' + article_cn + '\n')
            self.history_article.insert("end", '\n')
            end = self.history_article.index('end') + "-1l"
            self.history_article.tag_add("SENDBYME", start, end)
            self.history_article.tag_config("SENDBYME", foreground='Blue')