Skip to content

Commit ffabb75

Browse files
WEIFENG2333claudehappy-otter
committed
docs: add inference progress callback to README
Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
1 parent ae04109 commit ffabb75

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ Model names are automatically resolved to the correct hub (ModelScope in China,
296296
| `load_model(model, ...)` | `Model` | Load a model, returns a `Model` handle. |
297297
| `health()` | `dict` | Check server status. |
298298
| `list_models()` | `dict` | List loaded models. |
299+
| `get_progress(name)` | `dict` | Get inference progress `{"current", "total"}`. |
299300
| `execute(code)` | `dict` | Execute Python code on the server. |
300301

301302
### `load_model()` Parameters
@@ -331,6 +332,9 @@ result = model(audio="file.wav")
331332
# Alias for ASR
332333
result = model.transcribe(audio="file.wav")
333334

335+
# Progress query
336+
progress = model.get_progress() # {"current": 3, "total": 10}
337+
334338
# Unload from memory
335339
model.unload()
336340
```
@@ -348,6 +352,33 @@ model.unload()
348352
| `hotword` | `str` | Hotword string for biased recognition |
349353
| `merge_vad` | `bool` | Merge short VAD segments |
350354
| `merge_length_s` | `float` | Max merge length in seconds (default: 15) |
355+
| `progress_callback` | `callable` | Progress callback `(current, total) -> None` |
356+
357+
### Inference Progress
358+
359+
You can track inference progress using `progress_callback`:
360+
361+
```python
362+
model = asr.load_model("SenseVoiceSmall", vad_model="fsmn-vad")
363+
364+
def on_progress(current, total):
365+
if total > 0:
366+
print(f"\rProgress: {current}/{total} ({current/total*100:.0f}%)", end="")
367+
368+
result = model.infer(audio="long_meeting.wav", progress_callback=on_progress)
369+
```
370+
371+
When `progress_callback` is provided, inference runs in a background thread while the client polls the server every 0.5s for progress updates. The callback receives `(current, total)` where `current` is the number of completed batches and `total` is the total number of batches.
372+
373+
You can also query progress manually (e.g. from another thread):
374+
375+
```python
376+
progress = model.get_progress() # {"current": 3, "total": 10}
377+
```
378+
379+
When no inference is running, returns `{"current": 0, "total": 0}`.
380+
381+
> **Note:** Progress granularity depends on the number of VAD segments. Short audio with few segments may only show 0/0 → 1/1. Longer audio (e.g. meetings) with many VAD segments will produce finer-grained progress updates.
351382
352383
## Architecture
353384

0 commit comments

Comments
 (0)