> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qingbo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Speech Recognition & Translation

> Speech-to-text (STT) and speech translation

Synchronous endpoint — returns the recognition result directly when the request completes.

<RequestExample>
  ```bash cURL theme={"system"}
  curl https://www.qingbo.dev/v1/audio/transcriptions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F file="@audio.mp3" \
    -F model="whisper-1"
  ```

  ```python Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://www.qingbo.dev/v1",
      api_key="YOUR_API_KEY"
  )

  with open("audio.mp3", "rb") as f:
      transcript = client.audio.transcriptions.create(
          model="whisper-1",
          file=f
      )

  print(transcript.text)
  ```

  ```javascript JavaScript theme={"system"}
  import OpenAI from 'openai';
  import fs from 'fs';

  const client = new OpenAI({
    baseURL: 'https://www.qingbo.dev/v1',
    apiKey: 'YOUR_API_KEY'
  });

  const transcript = await client.audio.transcriptions.create({
    model: 'whisper-1',
    file: fs.createReadStream('audio.mp3')
  });

  console.log(transcript.text);
  ```

  ```go Go theme={"system"}
  package main

  import (
      "bytes"
      "fmt"
      "io"
      "mime/multipart"
      "net/http"
      "os"
  )

  func main() {
      file, _ := os.Open("audio.mp3")
      defer file.Close()

      body := &bytes.Buffer{}
      writer := multipart.NewWriter(body)
      part, _ := writer.CreateFormFile("file", "audio.mp3")
      io.Copy(part, file)
      writer.WriteField("model", "whisper-1")
      writer.Close()

      req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/audio/transcriptions", body)
      req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
      req.Header.Set("Content-Type", writer.FormDataContentType())

      resp, _ := http.DefaultClient.Do(req)
      defer resp.Body.Close()
      result, _ := io.ReadAll(resp.Body)
      fmt.Println(string(result))
  }
  ```

  ```java Java theme={"system"}
  import java.net.http.*;
  import java.net.URI;
  import java.nio.file.*;

  public class Main {
      public static void main(String[] args) throws Exception {
          String boundary = "----FormBoundary" + System.currentTimeMillis();
          byte[] fileBytes = Files.readAllBytes(Path.of("audio.mp3"));

          String body = "--" + boundary + "\r\n"
              + "Content-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\n"
              + "Content-Type: audio/mpeg\r\n\r\n";
          String fieldPart = "\r\n--" + boundary + "\r\n"
              + "Content-Disposition: form-data; name=\"model\"\r\n\r\nwhisper-1\r\n"
              + "--" + boundary + "--\r\n";

          byte[] requestBody = new byte[body.getBytes().length + fileBytes.length + fieldPart.getBytes().length];
          System.arraycopy(body.getBytes(), 0, requestBody, 0, body.getBytes().length);
          System.arraycopy(fileBytes, 0, requestBody, body.getBytes().length, fileBytes.length);
          System.arraycopy(fieldPart.getBytes(), 0, requestBody, body.getBytes().length + fileBytes.length, fieldPart.getBytes().length);

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create("https://www.qingbo.dev/v1/audio/transcriptions"))
              .header("Authorization", "Bearer YOUR_API_KEY")
              .header("Content-Type", "multipart/form-data; boundary=" + boundary)
              .POST(HttpRequest.BodyPublishers.ofByteArray(requestBody))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());
          System.out.println(response.body());
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"system"}
  {
    "text": "欢迎使用 清波 API 语音识别服务。"
  }
  ```
</ResponseExample>

## Available Models

| Model ID    | Description                                       |
| ----------- | ------------------------------------------------- |
| `whisper-1` | OpenAI Whisper, supports multilingual recognition |

## Two Endpoints

### Speech-to-text

```
POST /v1/audio/transcriptions
```

Transcribe audio into text in its original language.

### Speech translation

```
POST /v1/audio/translations
```

Translate audio into English text. Parameters are the same as the transcription endpoint.

## Request Parameters

Use the `multipart/form-data` format:

<ParamField body="file" type="file" required>
  Audio file. Supported formats: mp3, mp4, mpeg, mpga, m4a, wav, webm.
</ParamField>

<ParamField body="model" type="string" required>
  Model ID: `whisper-1`
</ParamField>

## Response

<ResponseField name="text" type="string">
  The recognized or translated text.
</ResponseField>
