Skip to content

Whisper语音转文字

This API is based on the Whisper model and provides speech-to-text functionality, supporting common audio formats.

  • Whisper model: OpenAI’s open-source speech recognition model, supporting multilingual transcription
  • Audio formats: Supports common formats such as mp3, wav, and m4a

POST https://api.4allapi.com/v1/audio/transcriptions

ParameterTypeRequiredDescription
modelstringYesFixed value "whisper-1"
filefileYesThe audio file to transcribe
Authorization: Bearer sk-********************* # replace with your API token
import json
import 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 usage
print(voice_to_text("audio.mp3")) # replace with the path to your audio file

Successful response:

{
"text": "This is the recognized text content"
}
  1. It is recommended that the audio file size not exceed 25MB
  2. Supports multiple languages, including Chinese and English
  3. Please keep your API key secure and do not disclose it

4All API · One-stop AI foundation model API aggregation platform | Pricing | Contact Us

© 2025 4All API. All rights reserved.