labring / FastGPT

FastGPT is a knowledge-based platform built on the LLMs, offers a comprehensive suite of out-of-the-box capabilities such as data processing, RAG retrieval, and visual AI workflow orchestration, letting you easily develop and deploy complex question-answering systems without the need for extensive setup or configuration.
https://tryfastgpt.ai
Other
17.44k stars 4.69k forks source link

用 FunASR 实时语音转录替代 Whisper 离线转录 #2183

Open zhanghx0905 opened 2 months ago

zhanghx0905 commented 2 months ago

例行检查

功能描述

当前的系统使用 Whisper 进行离线语音转录,这种方式存在中文效果一般,延迟大的问题。为了保证语音转录的实时性,提高用户体验,建议将现有的 Whisper 离线转录替换为 FunASR 实时语音转录。FunASR 提供了高效的实时语音转录功能,能够在保证准确率的同时,大幅度减少延迟。

应用场景

相关示例

为了便于集成和部署,可以使用已经打包成容器的 FunASR 实时语音转录 API,参见 https://harryai.cc/post/realtime-funasr/

这是一个为 harryliu888/funasr-online-server:latest 编写的客户端脚本,实时获取麦克风输入并转录:

import pyaudio
import websocket
import json
import threading

# 配置参数
config = {
    "chunk_size": [5, 10, 5],
    "wav_name": "h5",
    "is_speaking": True,
    "wav_format": "pcm",
    "chunk_interval": 10,
    "itn": True,
    "mode": "2pass",
    "hotwords": "",
}

# WebSocket URL
ws_url = "ws://10.223.48.160:10095/"  # 替换为你的服务端URL

# WebSocket连接
def on_message(ws, message):
    print(f"Received: {message}")

def on_error(ws, error):
    print(f"Error: {error}")

def on_close(ws, w, e):
    print("Connection closed")

def on_open(ws):
    def run(*args):
        # 发送配置参数
        ws.send(json.dumps(config))

        # 初始化pyaudio
        p = pyaudio.PyAudio()
        stream = p.open(
            format=pyaudio.paInt16,
            channels=1,
            rate=8000,
            input=True,
            frames_per_buffer=1024,
        )

        print("Recording...")

        try:
            while True:
                data = stream.read(1024)
                ws.send(data, opcode=websocket.ABNF.OPCODE_BINARY)
        except KeyboardInterrupt:
            pass

        # 发送结束标志
        end_signal = {"is_speaking": False}
        ws.send(json.dumps(end_signal))

        stream.stop_stream()
        stream.close()
        p.terminate()

        ws.close()

    threading.Thread(target=run).start()

if __name__ == "__main__":
    websocket.enableTrace(False)
    ws = websocket.WebSocketApp(
        ws_url,
        on_open=on_open,
        on_message=on_message,
        on_error=on_error,
        on_close=on_close,
    )
    ws.run_forever()

image

duskcouple commented 2 months ago

这个docker镜像能离线部署和运行吗?

zhanghx0905 commented 2 months ago

这个docker镜像能离线部署和运行吗?

可以。我希望修改fastgpt,适配funasr的websocket接口,在此寻求社区的帮助

duskcouple commented 2 months ago

这个docker镜像能离线部署和运行吗?

可以。我希望修改fastgpt,适配funasr的websocket接口,在此寻求社区的帮助

我pull你的镜像,跑了一下,确实很棒,fastgpt如果能集成适配接入你的websocket asr接口,语音输入体验一下子就高层次了,和智能就沾边了。 另外,问一下,你这镜像里的funasr是CPU版本的还是GPU版本的?

c121914yu commented 2 months ago

这个docker镜像能离线部署和运行吗?

可以。我希望修改fastgpt,适配funasr的websocket接口,在此寻求社区的帮助

直接修改成whisper 接口不就好了。线上都已经全部替换 funasr 了,拉阿里的代码,fastapi 改改完事~

zhanghx0905 commented 2 months ago

直接修改成whisper 接口不就好了。线上都已经全部替换 funasr 了,拉阿里的代码,fastapi 改改完事~

Whisper 的 API 不是实时流式识别,在语音输入结束之前,用户看不到自己说了什么;这与 funasr WebSocket 的实时识别还是有很大不同的。

c121914yu commented 2 months ago
WebSocketApp

不一定好,实时转,发现一个字错了,会打断讲话思路

zhanghx0905 commented 2 months ago

流式传输在某些场景下确实有优势,可以考虑提供为一个可选功能

zlj921020 commented 2 months ago

流式传输在某些场景下确实有优势,可以考虑提供为一个可选功能

大佬,实现了吗?

zhanghx0905 commented 2 months ago

流式传输在某些场景下确实有优势,可以考虑提供为一个可选功能

大佬,实现了吗?

没有,我目前觉得openai api的效果在识别足够准确时也不错,不搞流式了

RipperTs commented 2 months ago

这个在转写的过程中会自动纠错吗? 类似讯飞的实时转写接口那样

SDAIer commented 1 month ago

测试了下应该是不能

这个在转写的过程中会自动纠错吗? 类似讯飞的实时转写接口那样

测试了下应该不能