mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
* total_time/accum_grad * fp16 * update with main (#1817) * add cmakelist * add paraformer-torch * add debug for funasr-onnx-offline * fix redefinition of jieba StdExtension.hpp * add loading torch models * update funasr-onnx-offline * add SwitchArg for wss-server * add SwitchArg for funasr-onnx-offline * update cmakelist * update funasr-onnx-offline-rtf * add define condition * add gpu define for offlne-stream * update com define * update offline-stream * update cmakelist * update func CompileHotwordEmbedding * add timestamp for paraformer-torch * add C10_USE_GLOG for paraformer-torch * update paraformer-torch * fix func FunASRWfstDecoderInit * update model.h * fix func FunASRWfstDecoderInit * fix tpass_stream * update paraformer-torch * add bladedisc for funasr-onnx-offline * update comdefine * update funasr-wss-server * add log for torch * fix GetValue BLADEDISC * fix log * update cmakelist * update warmup to 10 * update funasrruntime * add batch_size for wss-server * add batch for bins * add batch for offline-stream * add batch for paraformer * add batch for offline-stream * fix func SetBatchSize * add SetBatchSize for model * add SetBatchSize for model * fix func Forward * fix padding * update funasrruntime * add dec reset for batch * set batch default value * add argv for CutSplit * sort frame_queue * sorted msgs * fix FunOfflineInfer * add dynamic batch for fetch * fix FetchDynamic * update run_server.sh * update run_server.sh * cpp http post server support (#1739) * add cpp http server * add some comment * remove some comments * del debug infos * restore run_server.sh * adapt to new model struct * 修复了onnxruntime在macos下编译失败的错误 (#1748) * Add files via upload 增加macos的编译支持 * Add files via upload 增加macos支持 * Add files via upload target_link_directories(funasr PUBLIC ${ONNXRUNTIME_DIR}/lib) target_link_directories(funasr PUBLIC ${FFMPEG_DIR}/lib) 添加 if(APPLE) 限制 --------- Co-authored-by: Yabin Li <wucong.lyb@alibaba-inc.com> * Delete docs/images/wechat.png * Add files via upload * fixed the issues about seaco-onnx timestamp * fix bug (#1764) 当语音识别结果包含 `http` 时,标点符号预测会把它会被当成 url * fix empty asr result (#1765) 解码结果为空的语音片段,text 用空字符串 * update export * update export * docs * docs * update export name * docs * update * docs * docs * keep empty speech result (#1772) * docs * docs * update wechat QRcode * Add python funasr api support for websocket srv (#1777) * add python funasr_api supoort * change little to README.md * add core tools stream * modified a little * fix bug for timeout * support for buffer decode * add ffmpeg decode for buffer * libtorch demo * update libtorch infer * update utils * update demo * update demo * update libtorch inference * update model class * update seaco paraformer * bug fix * bug fix * auto frontend * auto frontend * auto frontend * auto frontend * auto frontend * auto frontend * auto frontend * auto frontend * Dev gzf exp (#1785) * resume from step * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * train_loss_avg train_acc_avg * train_loss_avg train_acc_avg * train_loss_avg train_acc_avg * log step * wav is not exist * wav is not exist * decoding * decoding * decoding * wechat * decoding key * decoding key * decoding key * decoding key * decoding key * decoding key * dynamic batch * start_data_split_i=0 * total_time/accum_grad * total_time/accum_grad * total_time/accum_grad * update avg slice * update avg slice * sensevoice sanm * sensevoice sanm * sensevoice sanm --------- Co-authored-by: 北念 <lzr265946@alibaba-inc.com> * auto frontend * update paraformer timestamp * [Optimization] support bladedisc fp16 optimization (#1790) * add cif_v1 and cif_export * Update SDK_advanced_guide_offline_zh.md * add cif_wo_hidden_v1 * [fix] fix empty asr result (#1794) * english timestamp for valilla paraformer * wechat * [fix] better solution for handling empty result (#1796) * update scripts * modify the qformer adaptor (#1804) Co-authored-by: nichongjia-2007 <nichongjia@gmail.com> * add ctc inference code (#1806) Co-authored-by: haoneng.lhn <haoneng.lhn@alibaba-inc.com> * Update auto_model.py 修复空字串进入speaker model时报raw_text变量不存在的bug * Update auto_model.py 修复识别出空串后spk_model内变量未定义问题 * update model name * fix paramter 'quantize' unused issue (#1813) Co-authored-by: ZihanLiao <liaozihan1@xdf.cn> * wechat * Update cif_predictor.py (#1811) * Update cif_predictor.py * modify cif_v1_export under extreme cases, max_label_len calculated by batch_len misaligns with token_num * Update cif_predictor.py torch.cumsum precision degradation, using float64 instead * update code --------- Co-authored-by: 雾聪 <wucong.lyb@alibaba-inc.com> Co-authored-by: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com> Co-authored-by: szsteven008 <97944818+szsteven008@users.noreply.github.com> Co-authored-by: Ephemeroptera <605686962@qq.com> Co-authored-by: 彭震东 <zhendong.peng@qq.com> Co-authored-by: Shi Xian <40013335+R1ckShi@users.noreply.github.com> Co-authored-by: 维石 <shixian.shi@alibaba-inc.com> Co-authored-by: 北念 <lzr265946@alibaba-inc.com> Co-authored-by: xiaowan0322 <wanchen.swc@alibaba-inc.com> Co-authored-by: zhuangzhong <zhuangzhong@corp.netease.com> Co-authored-by: Xingchen Song(宋星辰) <xingchensong1996@163.com> Co-authored-by: nichongjia-2007 <nichongjia@gmail.com> Co-authored-by: haoneng.lhn <haoneng.lhn@alibaba-inc.com> Co-authored-by: liugz18 <57401541+liugz18@users.noreply.github.com> Co-authored-by: Marlowe <54339989+ZihanLiao@users.noreply.github.com> Co-authored-by: ZihanLiao <liaozihan1@xdf.cn> Co-authored-by: zhong zhuang <zhuangz@lamda.nju.edu.cn> * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * v1.0.28 (#1836) * sensevoice * sensevoice * sensevoice * sensevoice * sensevoice * update (#1841) * v1.0.28 * version checker * version checker * rollback cif_v1 for training bug * fixbug * fixbug for cif * fixbug --------- Co-authored-by: 维石 <shixian.shi@alibaba-inc.com> * update (#1842) * v1.0.28 * version checker * version checker * rollback cif_v1 for training bug * fixbug * fixbug for cif * fixbug --------- Co-authored-by: 维石 <shixian.shi@alibaba-inc.com> * inference * inference * inference * requests * finetune * finetune * finetune * finetune * finetune * add inference prepare func (#1848) * docs * docs * docs * docs * docs --------- Co-authored-by: 雾聪 <wucong.lyb@alibaba-inc.com> Co-authored-by: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com> Co-authored-by: szsteven008 <97944818+szsteven008@users.noreply.github.com> Co-authored-by: Ephemeroptera <605686962@qq.com> Co-authored-by: 彭震东 <zhendong.peng@qq.com> Co-authored-by: Shi Xian <40013335+R1ckShi@users.noreply.github.com> Co-authored-by: 维石 <shixian.shi@alibaba-inc.com> Co-authored-by: 北念 <lzr265946@alibaba-inc.com> Co-authored-by: xiaowan0322 <wanchen.swc@alibaba-inc.com> Co-authored-by: zhuangzhong <zhuangzhong@corp.netease.com> Co-authored-by: Xingchen Song(宋星辰) <xingchensong1996@163.com> Co-authored-by: nichongjia-2007 <nichongjia@gmail.com> Co-authored-by: haoneng.lhn <haoneng.lhn@alibaba-inc.com> Co-authored-by: liugz18 <57401541+liugz18@users.noreply.github.com> Co-authored-by: Marlowe <54339989+ZihanLiao@users.noreply.github.com> Co-authored-by: ZihanLiao <liaozihan1@xdf.cn> Co-authored-by: zhong zhuang <zhuangz@lamda.nju.edu.cn> Co-authored-by: PerfeZ <90945395+PerfeZ@users.noreply.github.com>
140 lines
3.8 KiB
Python
140 lines
3.8 KiB
Python
# coding=utf-8
|
|
|
|
import librosa
|
|
import base64
|
|
import io
|
|
import gradio as gr
|
|
import re
|
|
|
|
import numpy as np
|
|
import torch
|
|
import torchaudio
|
|
|
|
# from modelscope import HubApi
|
|
#
|
|
# api = HubApi()
|
|
#
|
|
# api.login('')
|
|
|
|
from funasr import AutoModel
|
|
|
|
# model = "/Users/zhifu/Downloads/modelscope_models/SenseVoiceCTC"
|
|
# model = "iic/SenseVoiceCTC"
|
|
# model = AutoModel(model=model,
|
|
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
|
|
# vad_kwargs={"max_single_segment_time": 30000},
|
|
# trust_remote_code=True,
|
|
# )
|
|
|
|
import re
|
|
import os
|
|
import sys
|
|
|
|
if len(sys.argv) > 1:
|
|
ckpt_dir = sys.argv[1]
|
|
ckpt_id = sys.argv[2]
|
|
jsonl = sys.argv[3]
|
|
output_dir = sys.argv[4]
|
|
device = sys.argv[5]
|
|
new_sys = False
|
|
if len(sys.argv) > 6:
|
|
new_sys = True
|
|
else:
|
|
ckpt_dir = "/nfs/beinian.lzr/workspace/GPT-4o/Exp/exp7/5m-8gpu/exp5-1-0619"
|
|
ckpt_id = "model.pt.ep6"
|
|
jsonl = (
|
|
"/nfs/beinian.lzr/workspace/GPT-4o/Data/Speech2Text/TestData/s2tchat.v20240619.test.jsonl"
|
|
)
|
|
dataset = jsonl.split("/")[-1]
|
|
output_dir = os.path.join(ckpt_dir, f"inference-{ckpt_id}", dataset)
|
|
|
|
|
|
model = AutoModel(
|
|
model=ckpt_dir,
|
|
init_param=f"{os.path.join(ckpt_dir, ckpt_id)}",
|
|
output_dir=output_dir,
|
|
device=device,
|
|
fp16=False,
|
|
bf16=False,
|
|
llm_dtype="bf16",
|
|
)
|
|
|
|
|
|
def model_inference(input_wav, text_inputs, fs=16000):
|
|
|
|
if isinstance(input_wav, tuple):
|
|
fs, input_wav = input_wav
|
|
input_wav = input_wav.astype(np.float32) / np.iinfo(np.int16).max
|
|
if len(input_wav.shape) > 1:
|
|
input_wav = input_wav.mean(-1)
|
|
if fs != 16000:
|
|
print(f"audio_fs: {fs}")
|
|
resampler = torchaudio.transforms.Resample(fs, 16000)
|
|
input_wav_t = torch.from_numpy(input_wav).to(torch.float32)
|
|
input_wav = resampler(input_wav_t[None, :])[0, :].numpy().astype("float32")
|
|
|
|
input_wav_byte = input_wav.tobytes()
|
|
|
|
contents_i = []
|
|
system_prompt = text_inputs
|
|
user_prompt = f"<|startofspeech|>!!{input_wav_byte}<|endofspeech|>"
|
|
contents_i.append({"role": "system", "content": system_prompt})
|
|
contents_i.append({"role": "user", "content": user_prompt})
|
|
contents_i.append({"role": "assistant", "content": "target_out"})
|
|
|
|
res = model.generate(
|
|
input=[contents_i],
|
|
tearchforing=tearchforing,
|
|
cache={},
|
|
key=key,
|
|
)
|
|
|
|
print(res)
|
|
|
|
return res
|
|
|
|
|
|
audio_examples = [
|
|
[
|
|
"https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/BAC009S0764W0121.wav",
|
|
"You are a helpful assistant.",
|
|
],
|
|
]
|
|
|
|
description = """
|
|
Upload an audio file or input through a microphone, then type te System Prompt.
|
|
|
|
|
|
"""
|
|
|
|
|
|
def launch():
|
|
with gr.Blocks() as demo:
|
|
gr.Markdown(description)
|
|
with gr.Row():
|
|
with gr.Column():
|
|
audio_inputs = gr.Audio(label="Upload audio or use the microphone")
|
|
text_inputs = gr.Text(label="System Prompt", value="You are a helpful assistant.")
|
|
|
|
# with gr.Accordion("Configuration"):
|
|
# # task_inputs = gr.Radio(choices=["Speech Recognition", "Rich Text Transcription"],
|
|
# # value="Speech Recognition", label="Task")
|
|
# language_inputs = gr.Dropdown(choices=["auto", "zh", "en", "yue", "ja", "ko", "nospeech"],
|
|
# value="auto",
|
|
# label="Language")
|
|
gr.Examples(examples=audio_examples, inputs=[audio_inputs, text_inputs])
|
|
|
|
fn_button = gr.Button("Start")
|
|
|
|
text_outputs = gr.HTML(label="Results")
|
|
|
|
fn_button.click(model_inference, inputs=[audio_inputs, text_inputs], outputs=text_outputs)
|
|
# with gr.Accordion("More examples"):
|
|
# gr.HTML(centered_table_html)
|
|
demo.launch()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# iface.launch()
|
|
launch()
|