46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
import torch
|
|
from funasr import AutoModel
|
|
|
|
|
|
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"
|
|
)
|
|
model = AutoModel(
|
|
model=model_dir,
|
|
trust_remote_code=True,
|
|
remote_code="./model.py",
|
|
device=device,
|
|
)
|
|
|
|
wav_path = f"{model.model_path}/example/zh.mp3"
|
|
res = model.generate(
|
|
input=[wav_path],
|
|
cache={},
|
|
batch_size=1,
|
|
hotwords=["开放时间"],
|
|
language="zh", # auto, zh, en, ja
|
|
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()
|