### Install FunASR and Dependencies Source: https://funasr.com Install the necessary Python packages for FunASR, including PyTorch, vLLM, FastAPI, and others. This is a prerequisite for running the FunASR server and client applications. ```bash $ pip install torch torchaudio pip install funasr vllm fastapi uvicorn python-multipart ``` -------------------------------- ### Clone FunASR Repository and Start Real-time WS Server Source: https://funasr.com Clone the FunASR GitHub repository and run the Python script to start a WebSocket server for real-time audio transcription. This is required for real-time use cases. ```bash $ git clone https://github.com/modelscope/FunASR.git && cd FunASR $ python examples/industrial_data_pretraining/fun_asr_nano/serve_realtime_ws.py --port 10095 --language 中文 ``` -------------------------------- ### Start FunASR Server for Offline Transcription Source: https://funasr.com Launch the FunASR server for offline file transcription. This command starts the service on a specified port, ready to accept transcription requests. ```bash $ funasr-server --device cuda --port 8899 ``` -------------------------------- ### Start FunASR Server for OpenAI Compatible API Source: https://funasr.com Launch the FunASR server with the --device cuda flag to enable the OpenAI-compatible API endpoint. This allows AI frameworks to integrate with FunASR using standard OpenAI API calls. ```bash $ funasr-server --device cuda ``` -------------------------------- ### Call FunASR Transcription API using curl Source: https://funasr.com Send a POST request to the running FunASR server to transcribe an audio file. This example uses curl and specifies the audio file, model, and desired response format. ```bash $ curl -X POST http://localhost:8899/v1/audio/transcriptions \ -F "file=@meeting.wav" -F "model=fun-asr-nano" -F "response_format=verbose_json" ``` -------------------------------- ### Connect to Real-time WS Server using Python Client Source: https://funasr.com Use a Python script to connect to the running FunASR WebSocket server for real-time transcription. This allows for programmatic interaction with the streaming audio service. ```bash $ python client_python.py --server ws://localhost:10095 --mic ``` -------------------------------- ### OpenAI SDK Direct Call for Transcriptions Source: https://funasr.com This Python snippet shows how to use the OpenAI SDK to directly call the FunASR service for audio transcriptions. It configures the client with the FunASR base URL and API key, then sends an audio file for processing. ```python from openai import OpenAI client = OpenAI(base_url="http://localhost:8899/v1", api_key="x") result = client.audio.transcriptions.create( model="fun-asr-nano", file=open("meeting.wav", "rb") ) print(result.text) ``` -------------------------------- ### Call OpenAI Compatible API using Python SDK Source: https://funasr.com Use the OpenAI Python client library to interact with the FunASR server's OpenAI-compatible API. This demonstrates how to perform audio transcriptions with minimal code changes for existing OpenAI integrations. ```python from openai import OpenAI client = OpenAI(base_url="http://localhost:8899/v1", api_key="x") result = client.audio.transcriptions.create( model="fun-asr-nano", file=open("audio.wav", "rb"), response_format="verbose_json" ) print(result.text) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.