asr 语音识别方法 基于paddle的方法

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/3/17 16:25
# @Author : sparkle_code_guy
'''
conda create -n paddlespeech python=3.7 cudnn=7.6.5 cudatoolkit=10.1.243 ffmpeg x264
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install paddlespeech -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install gradio
'''
import paddle
import gradio as gr
from paddlespeech.cli.asr import ASRExecutor

asr_executor = ASRExecutor()

def recognize_txt(audio_input,record_input):

    if audio_input:
        audio_message = audio_input
    else:
        audio_message = record_input
    text = asr_executor(
        audio_file=audio_message,
        model='conformer_wenetspeech',
        lang='zh',
        sample_rate=16000,
        config=None,  # Set `config` and `ckpt_path` to None to use pretrained model.
        ckpt_path=None,

        force_yes=False,
        device=paddle.get_device())
    return text

audio_input = gr.components.Audio(label='upload',source="upload",type='filepath')
record_input = gr.components.Audio(label='record',source="microphone",type='filepath')
iface = gr.Interface(fn=recognize_txt, inputs=[audio_input,record_input], outputs="text")
iface.launch(share=False,server_name='0.0.0.0',server_port=30001)

源代码直通车参考:paddlespeech 功能测试: 逐步体验paddlespeech包的各个语音功能 (gitee.com)

遗留问题:

目前还未找到办法可以直接传入对应的流式数据或者narray,有想法的可以交流沟通

若使用gpu环境,效率提升特别明显,对gpu的使用需求也仅仅2.5G的显存空间

关于paddlegpu环境的配置参考:(3条消息) 使用anaconda 安装paddle gpu环境_会发paper的学渣的博客-CSDN博客

你可能感兴趣的:(深度学习基础,asr)