Spaces:
Running on Zero
Running on Zero
| """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() | |