> For the complete documentation index, see [llms.txt](https://ai-docs.fptcloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-docs.fptcloud.com/api-reference/ai-marketplace/api-reference/api-integration-speech-to-text-md.md).

# API Integration - Speech to text.md

> Bash script preprocessing utility for audio files

## Preprocess audio files

```bash
#!/bin/bash

# Install sox if not already installed
if ! command -v sox &> /dev/null; then
    echo "sox could not be found, installing..."
    sudo apt-get update
    sudo apt-get install -y sox
fi

# Check if the input file is provided
if [ -z "$1" ]; then
    echo "Usage: $0 <input_audio_file>"
    exit 1
fi

# Convert the audio file to WAV format
# 1 channel, 16kHz, 16-bit PCM
INPUT_FILE="$1"
OUTPUT_FILE="${INPUT_FILE%.*}_norm.wav"
sox "$INPUT_FILE" -c 1 -r 16000 -b 16 "$OUTPUT_FILE"
```

> API Reference for Speech to text

## Python

```python
from openai import OpenAI

BASE_URL = "https://mkp-api.fptcloud.com"
API_KEY = "your-api-key"
MODEL_NAME = "your-model-name"
LANGUAGE = 'en'

client = OpenAI(api_key=API_KEY, 
                base_url=BASE_URL)

file = "speech.wav"
# file = "speech.mp3"
with open(file, "rb") as audio_file:
    data = audio_file.read()
    response = client.audio.transcriptions.create(
        model=MODEL_NAME,
        file=data,
        language=LANGUAGE,
        timeout=60,
        response_format="json"
    )

    print(response.text)
```

## cURL

```shell
curl --request POST \
  --url https://mkp-api.fptcloud.com/v1/audio/transcriptions \
  --header "Authorization: Bearer your-api-key" \
  --form "model=your-model-name" \
  --form "file=@your-file-path.mp3" \
  --form "language=en" \
  --form "response_format=json" \
  --max-time 60
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai-docs.fptcloud.com/api-reference/ai-marketplace/api-reference/api-integration-speech-to-text-md.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
