Categorygithub.com/AssemblyAI/assemblyai-go-sdk
modulepackage
1.9.0
Repository: https://github.com/assemblyai/assemblyai-go-sdk.git
Documentation: pkg.go.dev

# README


CI Passing GitHub License Go Reference AssemblyAI Twitter AssemblyAI YouTube Discord

AssemblyAI Go SDK

A Go client library for accessing AssemblyAI.

Overview

Documentation

Visit our AssemblyAI API Documentation to get an overview of our models!

See the reference docs at pkg.go.dev.

Quickstart

Installation

go get github.com/AssemblyAI/assemblyai-go-sdk

Examples

Before you begin, you need to have your API key. If you don't have one yet, sign up for one!

Core Transcription

Transcribe an audio file from URL
package main

import (
    "context"
    "log"
    "os"

    "github.com/AssemblyAI/assemblyai-go-sdk"
)

func main() {
    apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

    ctx := context.Background()

    audioURL := "https://example.org/audio.mp3"

    client := assemblyai.NewClient(apiKey)

    transcript, err := client.Transcripts.TranscribeFromURL(ctx, audioURL, nil)
    if err != nil {
        log.Fatal("Something bad happened:", err)
    }

    log.Println(*transcript.Text)
}
Transcribe a local audio file
package main

import (
    "context"
    "log"
    "os"

    "github.com/AssemblyAI/assemblyai-go-sdk"
)

func main() {
    apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

    ctx := context.Background()

    client := assemblyai.NewClient(apiKey)

    f, err := os.Open("./my-local-audio-file.wav")
    if err != nil {
        log.Fatal("Couldn't open audio file:", err)
    }
    defer f.Close()

    transcript, err := client.Transcripts.TranscribeFromReader(ctx, f, nil)
    if err != nil {
        log.Fatal("Something bad happened:", err)
    }

    log.Println(*transcript.Text)
}

Audio Intelligence

Identify entities in a transcript
package main

import (
    "context"
    "log"
    "os"

    "github.com/AssemblyAI/assemblyai-go-sdk"
)

func main() {
    apiKey := os.Getenv("ASSEMBLYAI_API_KEY")

    ctx := context.Background()

    audioURL := "https://example.org/audio.mp3"

    client := assemblyai.NewClient(apiKey)

    opts := &assemblyai.TranscriptParams{
        EntityDetection: assemblyai.Bool(true),
    }

    transcript, err := client.Transcripts.TranscribeFromURL(ctx, audioURL, opts)
    if err != nil {
        log.Fatal("Something bad happened:", err)
    }

    for _, entity := range transcript.Entities {
        log.Println(*entity.Text)
        log.Println(entity.EntityType)
        log.Printf("Timestamp: %v - %v", *entity.Start, *entity.End)
    }
}

Real-Time Transcription

Check out the realtime example.

Playgrounds

Visit one of our Playgrounds:

Tips and tricks

Inspect API errors

If you receive an API error, you can inspect the HTTP response returned by the API for more details:

transcript, err := client.Transcripts.TranscribeFromURL(ctx, audioURL, nil)
if err != nil {
    var apierr aai.APIError
    if errors.As(err, &apierr) {
        // apierr.Response is the *http.Response from the API call.
        fmt.Println(apierr.Response.StatusCode)
    } else {
        // err is not an API error.
    }
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
NewClient returns a new authenticated AssemblyAI client.
NewClientWithOptions returns a new configurable AssemblyAI client.
NewRealTimeClient returns a new instance of [RealTimeClient] with default values.
NewRealTimeClientWithOptions returns a new instance of [RealTimeClient].
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithAPIKey sets the API key used for authentication.
WithBaseURL sets the API endpoint used by the client.
WithHandler configures the client to use the provided handler to handle real-time events.
WithHTTPClient sets the http.Client used for making requests to the API.
WithRealTimeAuthToken configures the client to authenticate using an AssemblyAI API key.
WithRealTimeAuthToken configures the client to authenticate using a temporary token generated using [CreateTemporaryToken].
WithRealTimeBaseURL sets the API endpoint used by the client.
WithRealTimeEncoding specifies the encoding of the audio data.
WithRealTimeSampleRate sets the sample rate for the audio data.
No description provided by the author
WithRealTimeWordBoost sets the word boost for the real-time transcription.
WithUserAgent sets the user agent used by the client.

# Constants

Claude 2.0 is a legacy model that has good complex reasoning.
Claude 2.1 is a legacy model similar to Claude 2.0.
Claude 3.5 Sonnet is the most intelligent model to date, outperforming Claude 3 Opus on a wide range of evaluations, with the speed and cost of Claude 3 Sonnet.
Claude 3 Haiku is the fastest model that can execute lightweight actions.
Claude 3 Opus is good at handling complex analysis, longer tasks with many steps, and higher-order math and coding tasks.
Claude 3 Sonnet is a legacy model with a balanced combination of performance and speed for efficient, high-throughput tasks.
Claude Instant is a legacy model that is optimized for speed and cost.
Mistral 7B is an open source model that works well for summarization and answering questions.
Legacy model.
Legacy model.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PCM Mu-law.
PCM signed 16-bit little-endian (default).
The best model optimized for accuracy.
Conformer-2 is a heavy-duty model optimized for accuracy.
A lightweight, lower cost model for a wide range of languages.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
ErrConnectionNotFound is returned when attempting to disconnect a nil connection.
ErrDisconnected is returned when attempting to write to a disconnected client.
ErrSessionClosed is returned when attempting to write to a closed session.

# Structs

APIError represents an error returned by the AssemblyAI API.
No description provided by the author
No description provided by the author
An array of results for the Key Phrases model, if it is enabled.
Chapter of the audio file.
Client manages the communication with the AssemblyAI API.
No description provided by the author
No description provided by the author
An array of results for the Content Moderation model, if it is enabled.
No description provided by the author
A detected entity.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
An answer generated by LeMUR and its question.
No description provided by the author
No description provided by the author
LeMURService groups the operations related to LeMUR.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The usage numbers for the LeMUR request.
No description provided by the author
Details of the transcript page.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RealTimeService groups operations related to the real-time transcription.
No description provided by the author
No description provided by the author
The notification when the redacted audio is ready.
No description provided by the author
No description provided by the author
The result of the Sentiment Analysis model.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Timestamp containing a start and end property in milliseconds.
The result of the Topic Detection model, if it is enabled.
The result of the topic detection model.
A transcript object.
Object containing words or phrases to replace, and the word or phrase to replace with.
No description provided by the author
A list of transcripts.
No description provided by the author
The parameters for creating a transcript.
No description provided by the author
The parameters for creating a transcript.
The notification when the transcript status is completed or error.
No description provided by the author
TranscriptService groups the operations related to transcribing audio.
No description provided by the author
The notifications sent to the webhook URL.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Deprecated.

# Type aliases

Either success, or unavailable in the rare case that the model failed.
ClientOption lets you configure the AssemblyAI client.
The type of entity for the detected entity.
The model that is used for the final prompt after compression is performed.
No description provided by the author
The type of PII to redact.
No description provided by the author
RealTimeEncoding is the encoding format for the audio data.
The status of the redacted audio.
Controls the filetype of the audio created by redact_pii_audio.
No description provided by the author
The speech model to use for the transcription.
The replacement logic for detected PII, can be "entity_name" or "hash".
Format of the subtitles.
The model to summarize the transcript.
The type of summary.
How much to boost specified words.
The language of your audio file.
The status of the transcript.
The status of your transcript.
An array of timestamps structured as [`start_time`, `end_time`] in milliseconds.