Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ funasr audio.wav --output-format srt --output-dir ./subs
| Option | Short | Default | Description |
|--------|-------|---------|-------------|
| `--model` | `-m` | sensevoice | Model: sensevoice, paraformer, paraformer-en, fun-asr-nano |
| `--hub` | `-H` | ms | Model hub: ms (ModelScope) or hf (Hugging Face) |
| `--language` | `-l` | auto | Language: zh, en, ja, ko, yue, auto |
| `--device` | | auto | Device: cuda:0, cpu |
| `--output-format` | `-f` | text | Output: text, json, srt, tsv |
Expand Down Expand Up @@ -91,6 +92,9 @@ funasr audio.wav --model paraformer --language zh --hotwords "FunASR,达摩院"
# Pipe to jq for processing
funasr audio.wav -f json | jq '.text'

# Load models from Hugging Face instead of ModelScope
funasr audio.wav --hub hf --model fun-asr-nano

# Use with AI agents
result=$(funasr audio.wav -f json)
echo "$result" | jq -r '.text'
Expand Down
5 changes: 4 additions & 1 deletion funasr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ def main():
" funasr audio.wav\n"
" funasr audio.wav --model sensevoice -f json\n"
" funasr audio.wav -f srt -o ./subs\n"
" funasr audio.wav --spk --timestamps\n",
" funasr audio.wav --spk --timestamps\n"
" funasr audio.wav --hub hf --model fun-asr-nano\n",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
p.add_argument("audio", nargs="+", help="Audio file(s) to transcribe")
p.add_argument("--model", "-m", default="sensevoice", choices=list(MODEL_CONFIGS), help="Model (default: sensevoice)")
p.add_argument("--hub", "-H", default="ms", choices=["ms", "hf"], help="Model hub: ms (ModelScope) or hf (Hugging Face). Default: ms")
p.add_argument("--language", "-l", default=None, help="Language: zh, en, ja, ko, yue, auto")
p.add_argument("--device", default=None, help="Device: cuda:0, cpu (default: auto)")
p.add_argument("--output-format", "-f", default="text", choices=["text", "json", "srt", "tsv"], help="Output format (default: text)")
Expand All @@ -110,6 +112,7 @@ def main():

device = args.device or ("cuda:0" if torch.cuda.is_available() else "cpu")
config = MODEL_CONFIGS[args.model].copy()
config["hub"] = args.hub
if args.spk and "spk_model" not in config:
config["spk_model"] = "cam++"
if "punc_model" not in config and args.model not in ("fun-asr-nano", "sensevoice"):
Expand Down
41 changes: 41 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import io
import sys
import types
from contextlib import redirect_stdout
from unittest.mock import patch

from funasr import cli


class DummyAutoModel:
instances = []

def __init__(self, **kwargs):
self.kwargs = kwargs
self.instances.append(self)

def generate(self, **kwargs):
return [{"text": "hello"}]


def test_cli_passes_hub_to_auto_model(tmp_path):
audio_path = tmp_path / "sample.wav"
audio_path.write_bytes(b"not a real wav")
fake_torch = types.SimpleNamespace(
cuda=types.SimpleNamespace(is_available=lambda: False),
)

DummyAutoModel.instances = []
argv = ["funasr", "--hub", "hf", str(audio_path)]

with (
patch.object(sys, "argv", argv),
patch.dict(sys.modules, {"torch": fake_torch}),
patch("funasr.AutoModel", DummyAutoModel),
redirect_stdout(io.StringIO()) as stdout,
):
cli.main()

assert DummyAutoModel.instances[0].kwargs["hub"] == "hf"
assert stdout.getvalue().strip() == "hello"