Transcribe Short Audio
Make sure you have completed Quickstart step before proceeding with this guide.
In this example, we will transcribe a short audio (< 60 seconds) using the transcribe_file_short()
function and print out the recognized words.
from soniox.transcribe_file import transcribe_file_short
from soniox.speech_service import SpeechClient, set_api_key
set_api_key("<YOUR-API-KEY>")
def main():
with SpeechClient() as client:
result = transcribe_file_short("../test_data/test_audio.flac", client)
for word in result.words:
print(f"{word.text} {word.start_ms} {word.duration_ms}")
if __name__ == "__main__":
main()
We create a SpeechClient
object which handles all the communication between your program and Soniox Cloud. We use the with
statement to cleanup the client
object after it is no longer needed.
We then call the transcribe_file_short()
function with the created client
object and a short audio
file test_audio.flac
(part of soniox_examples GitHub repository).
The function reads the entire audio file and sends it to Soniox Cloud for transcription.
It returns an instance of the Result
structure, which contains the recognized words. Each word is an instance of the Word
structure, which contains the text of the recognized word as well as its timestamps.
Run
python3 transcribe_file_short.py
Output
He 180 60
was 420 60
two 660 60
...
In this example, we will transcribe a short audio (< 60 seconds) using the transcribeFileShort()
function and print out the recognized words.
const { SpeechClient } = require("@soniox/soniox-node");
/**
* Set your Soniox API key:
* from command line: export SONIOX_API_KEY=<YOUR-API-KEY>
* or
* pass config object: new SpeechClient({ api_key: "<YOUR-API-KEY>" })
*/
const speechClient = new SpeechClient();
(async function () {
const result = await speechClient.transcribeFileShort(
"../test_data/test_audio.flac"
);
for (const word of result.words) {
console.log(`${word.text} ${word.start_ms} ${word.duration_ms}`);
}
})();
We create a SpeechClient
object which handles all the communication between your program and Soniox Cloud.
We then call the transcribeFileShort()
function with a short audio file test_audio.flac
(part of soniox_examples GitHub repository).
The function reads the entire audio file and sends it to Soniox Cloud for transcription.
It returns an instance of the Result
structure, which contains the recognized words. Each word is an instance of the Word
structure, which contains the text of the recognized word as well as its timestamps.
Run
node transcribe_file_short.js
Output
He 180 60
was 420 60
two 660 60
...
In this example, we will transcribe a short audio (< 60 seconds) using the TranscribeFileShort()
function and print out the recognized words.
using Soniox.Types;
using Soniox.Client;
using Soniox.Client.Proto;
using var client = new SpeechClient();
var completeResult = await client.TranscribeFileShort(
"../../test_data/test_audio.flac",
new TranscriptionConfig { });
Result result = (completeResult as SingleResult)!.Result;
foreach (var word in result.Words)
{
Console.WriteLine($"{word.Text} {word.StartMs} {word.DurationMs}");
}
We create a SpeechClient
object which handles all the communication between your program and Soniox Cloud.
We then call the transcribeFileShort()
function with a short audio file test_audio.flac
(part of soniox_examples GitHub repository).
The function reads the entire audio file and sends it to Soniox Cloud for transcription.
It returns an instance of the Result
structure, which contains the recognized words. Each word is an instance of the Word
structure, which contains the text of the recognized word as well as its timestamps.
Run
cd soniox_examples/csharp/TranscribeFileShort
dotnet run
Output
He 180 60
was 420 60
two 660 60
...