File size: 1,394 Bytes
338c6c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Example: call a deployed Qwen3 Forced Aligner Space via its API.

Usage:
    python examples/client_example.py <space-id-or-url> [audio] [text] [language]

    python examples/client_example.py your-username/qwen3-force-aligner
    python examples/client_example.py your-username/qwen3-force-aligner \\
        path/to/audio.wav "hello world" English

Requires: pip install gradio_client
"""

from __future__ import annotations

import sys

from gradio_client import Client, handle_file

DEFAULT_AUDIO = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen3-ASR-Repo/asr_zh.wav"
DEFAULT_TEXT = "甚至出现交易几乎停滞的情况。"
DEFAULT_LANGUAGE = "Chinese"


def main() -> None:
    if len(sys.argv) < 2:
        print(__doc__)
        raise SystemExit(1)

    space = sys.argv[1]
    audio = sys.argv[2] if len(sys.argv) > 2 else DEFAULT_AUDIO
    text = sys.argv[3] if len(sys.argv) > 3 else DEFAULT_TEXT
    language = sys.argv[4] if len(sys.argv) > 4 else DEFAULT_LANGUAGE

    client = Client(space)

    # handle_file() works for both local paths and remote URLs.
    table, raw_json = client.predict(
        audio=handle_file(audio),
        text=text,
        language=language,
        api_name="/align",
    )

    print("Table rows:")
    for row in table:
        print(" ", row)

    print("\nRaw JSON:")
    print(raw_json)


if __name__ == "__main__":
    main()