| | |
| | | def sample_rate_checking(audio_in: Union[str, bytes], audio_format: str): |
| | | r_audio_fs = None |
| | | |
| | | if audio_format == 'wav': |
| | | if audio_format == 'wav' or audio_format == 'scp': |
| | | r_audio_fs = get_sr_from_wav(audio_in) |
| | | elif audio_format == 'pcm' and isinstance(audio_in, bytes): |
| | | r_audio_fs = get_sr_from_bytes(audio_in) |
| | |
| | | fs = None |
| | | else: |
| | | audio, fs = torchaudio.load(fname) |
| | | elif audio_type == "scp": |
| | | with open(fname, encoding="utf-8") as f: |
| | | for line in f: |
| | | wav_path = line.split()[1] |
| | | fs = get_sr_from_wav(wav_path) |
| | | if fs is not None: |
| | | break |
| | | return fs |
| | | elif os.path.isdir(fname): |
| | | dir_files = os.listdir(fname) |
| | |
| | | |
| | | 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'] |