57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import torch
|
||
|
||
|
||
def main():
|
||
model_dir = "FunAudioLLM/Fun-ASR-Nano-2512"
|
||
device = (
|
||
"cuda:0"
|
||
if torch.cuda.is_available()
|
||
else "mps"
|
||
if torch.backends.mps.is_available()
|
||
else "cpu"
|
||
)
|
||
|
||
from funasr import AutoModel
|
||
|
||
model = AutoModel(
|
||
model=model_dir,
|
||
trust_remote_code=True,
|
||
remote_code="./model.py",
|
||
device=device,
|
||
# hub:download models from ms (for ModelScope) or hf (for Hugging Face).
|
||
hub="ms"
|
||
)
|
||
|
||
wav_path = f"{model.model_path}/example/zh.mp3"
|
||
res = model.generate(
|
||
input=[wav_path],
|
||
cache={},
|
||
batch_size=1,
|
||
hotwords=["开放时间"],
|
||
# 中文、英文、日文 for Fun-ASR-Nano-2512
|
||
# 中文、英文、粤语、日文、韩文、越南语、印尼语、泰语、马来语、菲律宾语、阿拉伯语、
|
||
# 印地语、保加利亚语、克罗地亚语、捷克语、丹麦语、荷兰语、爱沙尼亚语、芬兰语、希腊语、
|
||
# 匈牙利语、爱尔兰语、拉脱维亚语、立陶宛语、马耳他语、波兰语、葡萄牙语、罗马尼亚语、
|
||
# 斯洛伐克语、斯洛文尼亚语、瑞典语 for Fun-ASR-MLT-Nano-2512
|
||
language="中文",
|
||
itn=True, # or False
|
||
)
|
||
text = res[0]["text"]
|
||
print(text)
|
||
|
||
model = AutoModel(
|
||
model=model_dir,
|
||
trust_remote_code=True,
|
||
vad_model="fsmn-vad",
|
||
vad_kwargs={"max_single_segment_time": 30000},
|
||
remote_code="./model.py",
|
||
device=device,
|
||
)
|
||
res = model.generate(input=[wav_path], cache={}, batch_size=1)
|
||
text = res[0]["text"]
|
||
print(text)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|