|
| 1 | +--- |
| 2 | +layout: integration |
| 3 | +name: FunASR |
| 4 | +description: Transcribe audio files to Documents using FunASR — an open-source, self-hosted speech recognition toolkit supporting 50+ languages. |
| 5 | +authors: |
| 6 | + - name: deepset |
| 7 | + socials: |
| 8 | + github: deepset-ai |
| 9 | + twitter: Haystack_AI |
| 10 | + linkedin: https://www.linkedin.com/company/deepset-ai/ |
| 11 | +pypi: https://pypi.org/project/funasr-haystack/ |
| 12 | +repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/funasr |
| 13 | +type: Data Ingestion |
| 14 | +report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues |
| 15 | +version: Haystack 2.0 |
| 16 | +toc: true |
| 17 | +--- |
| 18 | + |
| 19 | +[](https://pypi.org/project/funasr-haystack/) |
| 20 | +[](https://pypi.org/project/funasr-haystack/) |
| 21 | +[](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/funasr.yml) |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +### Table of Contents |
| 26 | + |
| 27 | +- [Overview](#overview) |
| 28 | +- [Installation](#installation) |
| 29 | +- [Usage](#usage) |
| 30 | + - [FunASRTranscriber](#funasrtranscriber) |
| 31 | +- [License](#license) |
| 32 | + |
| 33 | +## Overview |
| 34 | + |
| 35 | +[FunASR](https://github.com/modelscope/FunASR) is an open-source speech recognition toolkit from Alibaba DAMO Academy that runs entirely locally — no API key required. It supports 50+ languages, speaker diarization, and timestamp extraction. |
| 36 | + |
| 37 | +This integration provides: |
| 38 | + |
| 39 | +- [`FunASRTranscriber`](https://docs.haystack.deepset.ai/docs/funasrtranscriber): Transcribes audio files to Haystack `Document` objects. Accepts file paths, `Path` objects, and `ByteStream` inputs. |
| 40 | + |
| 41 | +## Installation |
| 42 | + |
| 43 | +```bash |
| 44 | +pip install funasr-haystack |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +### FunASRTranscriber |
| 50 | + |
| 51 | +`FunASRTranscriber` transcribes audio files to Haystack `Document` objects using FunASR models. Models are downloaded from ModelScope on first use and cached in `~/.cache/modelscope`. |
| 52 | + |
| 53 | +#### Basic Example |
| 54 | + |
| 55 | +```python |
| 56 | +from haystack_integrations.components.audio.funasr import FunASRTranscriber |
| 57 | + |
| 58 | +transcriber = FunASRTranscriber() |
| 59 | + |
| 60 | +result = transcriber.run(sources=["speech.wav", "interview.mp3"]) |
| 61 | +for doc in result["documents"]: |
| 62 | + print(doc.content) |
| 63 | +``` |
| 64 | + |
| 65 | +#### In a Pipeline |
| 66 | + |
| 67 | +```python |
| 68 | +from haystack import Pipeline |
| 69 | +from haystack.components.fetchers import LinkContentFetcher |
| 70 | +from haystack_integrations.components.audio.funasr import FunASRTranscriber |
| 71 | + |
| 72 | +pipe = Pipeline() |
| 73 | +pipe.add_component("fetcher", LinkContentFetcher()) |
| 74 | +pipe.add_component("transcriber", FunASRTranscriber()) |
| 75 | + |
| 76 | +pipe.connect("fetcher", "transcriber") |
| 77 | + |
| 78 | +result = pipe.run( |
| 79 | + data={ |
| 80 | + "fetcher": { |
| 81 | + "urls": ["https://example.com/speech.wav"], |
| 82 | + }, |
| 83 | + } |
| 84 | +) |
| 85 | +print(result["transcriber"]["documents"][0].content) |
| 86 | +``` |
| 87 | + |
| 88 | +#### Speaker Diarization |
| 89 | + |
| 90 | +```python |
| 91 | +from haystack.utils import ComponentDevice |
| 92 | +from haystack_integrations.components.audio.funasr import FunASRTranscriber |
| 93 | + |
| 94 | +transcriber = FunASRTranscriber( |
| 95 | + model="paraformer-zh", |
| 96 | + vad_model="fsmn-vad", |
| 97 | + punc_model="ct-punc", |
| 98 | + spk_model="cam++", |
| 99 | + device=ComponentDevice.from_str("cuda"), |
| 100 | +) |
| 101 | + |
| 102 | +result = transcriber.run(sources=["meeting.wav"]) |
| 103 | +doc = result["documents"][0] |
| 104 | +print(doc.content) |
| 105 | +print("Speakers:", doc.meta.get("speakers")) |
| 106 | +``` |
| 107 | + |
| 108 | +## License |
| 109 | + |
| 110 | +`funasr-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. |
0 commit comments