微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何提高python语音识别的准确性?

如何解决如何提高python语音识别的准确性?

我想使用 SpeechRecognition 模块在离线模式下将一些音频文件转换为文本。我能够转换它,但它的准确率为 0%。谁能建议如何使其更准确? 这是我正在使用的代码

def convert_wav_to_text(path):
    """
    Splitting the large audio file into chunks
    and apply speech recognition on each of these chunks
    """
    # open the audio file using pydub
    sound = AudioSegment.from_wav(path)
    # split audio sound where silence is 700 miliseconds or more and get chunks
    chunks = split_on_silence(sound,# experiment with this value for your target audio file
        min_silence_len = 500,# adjust this per requirement
        silence_thresh = sound.dBFS-14,# keep the silence for 1 second,adjustable as well
        keep_silence=500,)
    folder_name = "audio-chunks"
    # create a directory to store the audio chunks
    if not os.path.isdir(folder_name):
        os.mkdir(folder_name)
    whole_text = ""
    # process each chunk
    for i,audio_chunk in enumerate(chunks,start=1):
        # export audio chunk and save it in
        # the `folder_name` directory.
        chunk_filename = os.path.join(folder_name,f"chunk{i}.wav")
        audio_chunk.export(chunk_filename,format="wav")
        # recognize the chunk
        with sr.AudioFile(chunk_filename) as source:
            audio_listened = r.record(source)
            # try converting it to text
            try:
                text = r.recognize_sphinx(audio_listened)
            except sr.UnkNownValueError as e:
                print("Error:",str(e))
            else:
                text = f"{text.capitalize()}. "
                whole_text += text
    # return the text for all chunks detected
    num = path.split('.')[0]
    file = open(num+'.txt','w')
    file.write(whole_text)
    file.close()

convert_wav_to_text("1.wav")

我还附上了音频文件1.wav

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。