Initial commit: FunASR Speech Recognition Toolkit
Update API Documentation / build-api-docs (push) Has been cancelled
Update API Documentation / build-api-docs (push) Has been cancelled
Add complete FunASR codebase including models, runtime, and documentation.
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# FunASR Colab Quickstart\n",
|
||||
"\n",
|
||||
"Run FunASR in a browser, transcribe a public sample, then try your own audio file.\n",
|
||||
"\n",
|
||||
"Repository: https://github.com/modelscope/FunASR\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1. Install dependencies\n",
|
||||
"\n",
|
||||
"The first cell can take a few minutes because it installs FunASR and downloads Python wheels. Colab already includes PyTorch in most runtimes.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip -q install -U funasr modelscope soundfile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2. Select CPU or GPU\n",
|
||||
"\n",
|
||||
"For a faster run, choose **Runtime -> Change runtime type -> GPU** in Colab before running the notebook.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import torch\n",
|
||||
"\n",
|
||||
"device = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n",
|
||||
"print(f\"Using device: {device}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3. Transcribe a public sample\n",
|
||||
"\n",
|
||||
"This uses `paraformer-zh` with VAD and punctuation so the example works with a short public Mandarin sample.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from funasr import AutoModel\n",
|
||||
"\n",
|
||||
"sample_url = \"https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/vad_example.wav\"\n",
|
||||
"\n",
|
||||
"model = AutoModel(\n",
|
||||
" model=\"paraformer-zh\",\n",
|
||||
" vad_model=\"fsmn-vad\",\n",
|
||||
" punc_model=\"ct-punc\",\n",
|
||||
" device=device,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"result = model.generate(input=sample_url, batch_size_s=60)\n",
|
||||
"print(json.dumps(result, ensure_ascii=False, indent=2))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4. Try your own audio file\n",
|
||||
"\n",
|
||||
"Upload a short `.wav`, `.mp3`, `.m4a`, or `.flac` file. For long recordings, split the audio or use a GPU runtime.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google.colab import files\n",
|
||||
"\n",
|
||||
"uploaded = files.upload()\n",
|
||||
"audio_path = next(iter(uploaded))\n",
|
||||
"print(f\"Uploaded: {audio_path}\")\n",
|
||||
"\n",
|
||||
"user_result = model.generate(input=audio_path, batch_size_s=60)\n",
|
||||
"print(json.dumps(user_result, ensure_ascii=False, indent=2))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5. Save the transcript JSON\n",
|
||||
"\n",
|
||||
"Attach this JSON when you open a GitHub issue or compare model outputs.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"Path(\"funasr_transcript.json\").write_text(\n",
|
||||
" json.dumps(user_result, ensure_ascii=False, indent=2),\n",
|
||||
" encoding=\"utf-8\",\n",
|
||||
")\n",
|
||||
"files.download(\"funasr_transcript.json\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Next steps\n",
|
||||
"\n",
|
||||
"- Choose a model: https://github.com/modelscope/FunASR/blob/main/docs/model_selection.md\n",
|
||||
"- Compare with Whisper or cloud ASR: https://github.com/modelscope/FunASR/blob/main/docs/migration_from_whisper.md\n",
|
||||
"- Deploy an OpenAI-compatible API: https://github.com/modelscope/FunASR/tree/main/examples/openai_api\n",
|
||||
"- Read production deployment options: https://github.com/modelscope/FunASR/blob/main/docs/deployment_matrix.md\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user