ballerinax/openai.audio Ballerina library

1.0.0

Overview

This is a generated connector for the OpenAI Audio API OpenAPI Specification. OpenAI is an American artificial intelligence research laboratory consisting of a non-profit corporation and a for-profit subsidiary. OpenAI conducts AI research with the declared intention of promoting and developing friendly AI. The OpenAI Audio API provides a way to access new speech-to-text AI models developed by OpenAI for a variety of tasks.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quick start

To use the OpenAI Audio connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the connector

First, import the ballerinax/openai.audio module into the Ballerina project.

Copy
import ballerinax/openai.audio;
import ballerina/io;

Step 2: Create a new connector instance

Create and initialize an audio:Client with the obtained apiKey.

Copy
audio:Client audioClient = check new ({
    auth: {
        token: "sk-XXXXXXXXX"
    }
});

Step 3: Invoke the connector operation

  1. Now you can use the operations available within the connector.

Note: The operations are in the form of remote operations.

Following is an example on transcribing audio using the OpenAI Whisper-1 model:

Transcribe with Whisper-1

```ballerina
public function main() returns error? {
    audio:CreateTranscriptionRequest req = {
        file: {fileContent: check io:fileReadBytes("sample.mp3"), fileName: "sample.mp3"},
        model: "whisper-1"
    };
    audio:CreateTranscriptionResponse|error unionResult = check audioClient->/audio/transcriptions.post(req);
    if unionResult is audio:CreateTranscriptionResponse {
        io:println(unionResult.text);
    } else {
        io:println(unionResult);
    }
}
``` 

2. Use bal run command to compile and run the Ballerina program.

Sample

Copy
import ballerinax/openai.audio;
import ballerina/io;

audio:Client audioClient = check new ({
    auth: {
        token: "sk-XXXXXXXXX"
    }
});

public function main() returns error? {
    audio:CreateTranscriptionRequest req = {
        file: {fileContent: check io:fileReadBytes("sample.mp3"), fileName: "sample.mp3"},
        model: "whisper-1"
    };
    audio:CreateTranscriptionResponse|error unionResult = check audioClient->/audio/transcriptions.post(req);
    if unionResult is audio:CreateTranscriptionResponse {
        io:println(unionResult.text);
    } else {
        io:println(unionResult);
    }
}

Import

import ballerinax/openai.audio;Copy

Metadata

Released date: about 1 year ago

Version: 1.0.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.0

GraalVM compatible: Yes


Pull count

Total: 27

Current verison: 2


Weekly downloads


Source repository


Keywords

AI/OpenAI

Cost/Paid

speech-to-text

whisper


Contributors

Other versions

See more...