Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex SpeechKit
  • SpeechKit technology overview
    • Speech recognition using Playground
    • Speech synthesis using Playground
      • Audio file streaming recognition, API v3
      • Microphone speech streaming recognition, API v3
      • Automatic language detection, API v3
      • Streaming recognition, API v2
      • Synchronous recognition, API v1
      • Asynchronous recognition of WAV audio files, API v3
      • Asynchronous recognition of LPCM format, API v2
      • Asynchronous recognition of OggOpus format, API v2
      • Regular asynchronous recognition of audio files, API v2
  • Supported audio formats
  • IVR integration
  • Quotas and limits
  • Access management
  • Pricing policy

In this article:

  • Request example
  • Response example
  1. Step-by-step guides
  2. Recognition
  3. Synchronous recognition, API v1

Example of using the API v1 for synchronous recognition

Written by
Yandex Cloud
Updated at February 10, 2025
  • Request example
  • Response example

The example shows how the API v1 helps synchronously recognize speech in the OggOpus audio file format.

The example uses the following parameters:

  • Language: Russian.
  • Other parameters are left at their defaults.

Use the cURL utility to generate and send a request to the server for recognition.

The Yandex account or federated account are authenticated using an IAM token. If using a service account, you do not need to include the folder ID in the request. Learn more about authentication in the SpeechKit API.

Request exampleRequest example

POST request
cURL
Python 3
PHP

Send a request to convert speech to text:

POST /speech/v1/stt:recognize?topic=general&lang=ru-RU&folderId={<folder_ID>} HTTP/1.1
Host: stt.api.cloud.yandex.net
Authorization: Bearer <IAM_token>

... (binary content of an audio file)

Where:

  • topic: Language model.
  • lang: Recognition language.
  • folderId: Folder ID.
  • <IAM_token>: IAM token.

Send a request to convert speech to text:

export FOLDER_ID=<folder_ID>
export IAM_TOKEN=<IAM_token>
curl \
  --request POST \
  --header "Authorization: Bearer ${IAM_TOKEN}" \
  --data-binary "@speech.ogg" \
  "https://stt.api.cloud.yandex.net/speech/v1/stt:recognize?topic=general&folderId=${FOLDER_ID}"

Where:

  • FOLDER_ID: Folder ID.
  • IAM_TOKEN: IAM token.
  • --data-binary: Name of the audio file for recognition.
  • topic: Language model.

Send a request to convert speech to text:

import urllib.request
import json

FOLDER_ID = "<folder_ID>" #: Folder ID.
IAM_TOKEN = "<IAM_token>>" #: IAM token.

with open("speech.ogg", "rb") as f:
    data = f.read()

params = "&".join([
    "topic=general",
    "folderId=%s" % FOLDER_ID,
    "lang=ru-RU"
])

url = urllib.request.Request("https://stt.api.cloud.yandex.net/speech/v1/stt:recognize?%s" % params, data=data)
# Authentication with an IAM token
url.add_header("Authorization", "Bearer %s" % IAM_TOKEN)

responseData = urllib.request.urlopen(url).read().decode('UTF-8')
decodedData = json.loads(responseData)

if decodedData.get("error_code") is None:
    print(decodedData.get("result"))

Where:

  • FOLDER_ID: Folder ID.
  • IAM_TOKEN: IAM token.
  • speech.ogg: Name of the audio file for recognition.
  • topic: Language model.
  • lang: Recognition language.

Send a request to convert speech to text:

<?php

$token = '<IAM_token>'; #: IAM token.
$folderId = "<folder_ID>"; #: Folder ID.
$audioFileName = "speech.ogg";

$file = fopen($audioFileName, 'rb');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://stt.api.cloud.yandex.net/speech/v1/stt:recognize?lang=ru-RU&folderId=${folderId}&format=oggopus");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($audioFileName));
$res = curl_exec($ch);
curl_close($ch);
$decodedResponse = json_decode($res, true);
if (isset($decodedResponse["result"])) {
    echo $decodedResponse["result"];
} else {
    echo "Error code: " . $decodedResponse["error_code"] . "\r\n";
    echo "Error message: " . $decodedResponse["error_message"] . "\r\n";
}

fclose($file);

Where:

  • token: IAM token.
  • folderId: Folder ID.
  • audioFileName: Name of the audio file for recognition.
  • lang: Recognition language.
  • format: Format of the submitted audio file.

Response exampleResponse example

HTTP/1.1 200 OK
YaCloud-Billing-Units: 15
{
  "result": "your number is 212-85-06"
}

See alsoSee also

  • Synchronous recognition API
  • Authentication with the SpeechKit API
  • Synchronous speech recognition using the Python SDK

Was the article helpful?

Previous
Streaming recognition, API v2
Next
Asynchronous recognition of WAV audio files, API v3
© 2025 Direct Cursus Technology L.L.C.