Whisper语音转文字
whisper Model API Reference
Section titled “whisper Model API Reference”This API is based on the Whisper model and provides speech-to-text functionality, supporting common audio formats.
Basic Concepts
Section titled “Basic Concepts”- Whisper model: OpenAI’s open-source speech recognition model, supporting multilingual transcription
- Audio formats: Supports common formats such as mp3, wav, and m4a
API Endpoint
Section titled “API Endpoint”POST https://api.4allapi.com/v1/audio/transcriptions
Request Parameters
Section titled “Request Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Fixed value "whisper-1" |
| file | file | Yes | The audio file to transcribe |
Request Headers
Section titled “Request Headers”Authorization: Bearer sk-********************* # replace with your API tokenPython Example
Section titled “Python Example”import jsonimport requests
def voice_to_text(file_path): """ Speech-to-text functionality
Parameters: file_path: path to the audio file
Returns: recognized text content """ url = "https://api.4allapi.com/v1/audio/transcriptions"
# Build request parameters payload = {"model": "whisper-1"} files = {"file": ("audio.mp3", open(file_path, "rb"))}
# Set request headers (replace with your API key) headers = {"Authorization": "Bearer sk-***************************"} # replace with your API token
# Send POST request response = requests.post(url, headers=headers, data=payload, files=files)
# Parse response data data = json.loads(response.text)
# Return the transcription result return data.get("text", "")
# Example usageprint(voice_to_text("audio.mp3")) # replace with the path to your audio fileResponse Example
Section titled “Response Example”Successful response:
{ "text": "This is the recognized text content"}- It is recommended that the audio file size not exceed 25MB
- Supports multiple languages, including Chinese and English
- Please keep your API key secure and do not disclose it
4All API Footer
Section titled “4All API Footer”4All API · One-stop AI foundation model API aggregation platform | Pricing | Contact Us
© 2025 4All API. All rights reserved.