> For the complete documentation index, see [llms.txt](https://iruca.gitbook.io/ope.ai-pod/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://iruca.gitbook.io/ope.ai-pod/features/speech-to-text-yu-yin-zhuan-wen-ben-gong-neng.md).

# Speech to text语音转文本功能

```python
from openai import OpenAI

apiKey  = "KEY"
baseURL = "https://testpod.ope.ai/v1"

client = OpenAI(api_key=apiKey, base_url=baseURL)

audio_file= open("/path/to/file/audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
  model="whisper-large-v3-turbo", 
  file=audio_file
)
print(transcription.text)
```

1. `open("/path/to/file/audio.mp3", "rb")`

打开音频文件（audio.mp3），其中`rb`代表只读二进制文件。

2. `client.audio.transcriptions.create`

调用api进行音频转录。`file`是上文的音频文件。目前可以选择的`model`有：

```python
  model="whisper-large-v3-turbo", 
```

3. `print(transcription.text)`

输出转录文本。

Curl调用的例子：

```python
curl --request POST \
  --url https://testpod.ope.ai/v1/audio/transcriptions \
  --header "Authorization: Bearer $OPENAI_API_KEY" \
  --header 'Content-Type: multipart/form-data' \
  --form file=@/path/to/file/audio.mp3 \
  --form model=whisper-large-v3-turbo
```
