| | |
| | | if r_recog_type is None and audio_in is not None: |
| | | # audio_in is wav, recog_type is wav_file |
| | | if os.path.isfile(audio_in): |
| | | audio_type = os.path.basename(audio_in).split(".")[1].lower() |
| | | audio_type = os.path.basename(audio_in).split(".")[-1].lower() |
| | | if audio_type in SUPPORT_AUDIO_TYPE_SETS: |
| | | r_recog_type = 'wav' |
| | | r_audio_format = 'wav' |
| | |
| | | def get_sr_from_wav(fname: str): |
| | | fs = None |
| | | if os.path.isfile(fname): |
| | | audio_type = os.path.basename(fname).split(".")[1].lower() |
| | | audio_type = os.path.basename(fname).split(".")[-1].lower() |
| | | if audio_type in SUPPORT_AUDIO_TYPE_SETS: |
| | | if audio_type == "pcm": |
| | | fs = None |
| | |
| | | for file in dir_files: |
| | | file_path = os.path.join(fname, file) |
| | | if os.path.isfile(file_path): |
| | | audio_type = os.path.basename(file_path).split(".")[1].lower() |
| | | audio_type = os.path.basename(file_path).split(".")[-1].lower() |
| | | if audio_type in SUPPORT_AUDIO_TYPE_SETS: |
| | | fs = get_sr_from_wav(file_path) |
| | | elif os.path.isdir(file_path): |
| | |
| | | file_path = os.path.join(dir_path, file) |
| | | if os.path.isfile(file_path): |
| | | if ends == ".wav" or ends == ".WAV": |
| | | audio_type = os.path.basename(file_path).split(".")[1].lower() |
| | | audio_type = os.path.basename(file_path).split(".")[-1].lower() |
| | | if audio_type in SUPPORT_AUDIO_TYPE_SETS: |
| | | return True |
| | | else: |
| | |
| | | for file in dir_files: |
| | | file_path = os.path.join(dir_path, file) |
| | | if os.path.isfile(file_path): |
| | | audio_type = os.path.basename(file_path).split(".")[1].lower() |
| | | audio_type = os.path.basename(file_path).split(".")[-1].lower() |
| | | if audio_type in SUPPORT_AUDIO_TYPE_SETS: |
| | | wav_list.append(file_path) |
| | | elif os.path.isdir(file_path): |
| | |
| | | |
| | | return wav_list |
| | | |
| | | |
| | | def set_parameters(language: str = None): |
| | | if language is not None: |
| | | global global_asr_language |
| | | global_asr_language = language |
| | | |
| | | |
| | | def compute_wer(hyp_list: List[Any], |
| | | ref_list: List[Any], |
| | | lang: str = None) -> Dict[str, Any]: |
| | | assert len(hyp_list) > 0, 'hyp list is empty' |
| | | assert len(ref_list) > 0, 'ref list is empty' |
| | | |
| | | if lang is not None: |
| | | global global_asr_language |
| | | global_asr_language = lang |
| | | |
| | | rst = { |
| | | 'Wrd': 0, |
| | |
| | | 'wrong_sentences': 0 |
| | | } |
| | | |
| | | if lang is None: |
| | | lang = global_asr_language |
| | | |
| | | for h_item in hyp_list: |
| | | for r_item in ref_list: |
| | | if h_item['key'] == r_item['key']: |
| | | out_item = compute_wer_by_line(h_item['value'], |
| | | r_item['value'], |
| | | global_asr_language) |
| | | lang) |
| | | rst['Wrd'] += out_item['nwords'] |
| | | rst['Corr'] += out_item['cor'] |
| | | rst['wrong_words'] += out_item['wrong'] |