whisper

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2023 License: CC0-1.0 Imports: 12 Imported by: 0

README

Whisper ASR API Client

This package provides a client for interacting with the OpenAI Whisper ASR API. It allows you to transcribe audio files using the Whisper ASR service.

Installation

To install the package, use the following command:

go get github.com/nmeilick/go-whisper

Usage

Here's a short example of how to use the package to transcribe an audio file:

package main

import (
	"fmt"
	"log"

	"github.com/nmeilick/go-whisper"
)

func main() {
	
	// by default, the key is read from OPENAI_API_KEY in env
	client := whisper.NewClient(whisper.WithKey("your-api-key"))

	response, err := client.TranscribeFile("path/to/your/audio/file.m4a")
	if err != nil {
		log.Fatalf("Error transcribing file: %v", err)
	}

	fmt.Printf("Transcription: %s\n", response.Text)
}

Documentation

For more information on the available methods and structures, please refer to the source code and comments.

Documentation

Overview

Package whisper provides a client for interacting with the OpenAI Whisper ASR API.

Index

Constants

View Source
const (
	DefaultBase  = "https://api.openai.com/v1"
	DefaultModel = "whisper-1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the main structure for interacting with the Whisper ASR API.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new Whisper ASR API client with the given options.

func (*Client) Transcribe

func (c *Client) Transcribe(h io.Reader, opts ...TranscribeOption) (*TranscribeResponse, error)

Transcribe transcribes the given audio stream using the Whisper ASR API.

func (*Client) TranscribeFile

func (c *Client) TranscribeFile(file string, opts ...TranscribeOption) (*TranscribeResponse, error)

TranscribeFile transcribes the given file using the Whisper ASR API.

func (*Client) URL

func (c *Client) URL(relPath string) string

URL constructs the full URL for the given relative path.

type ClientOption

type ClientOption func(*Client)

ClientOption is a function type that allows to set options for the Client.

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets the base URL for the Client.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets the HTTP client for the Client.

func WithKey

func WithKey(key string) ClientOption

WithKey sets the API key for the Client.

type Segment

type Segment struct {
	ID               int     `json:"id"`
	Seek             int     `json:"seek"`
	Start            float64 `json:"start"`
	End              float64 `json:"end"`
	Text             string  `json:"text"`
	Tokens           []int   `json:"tokens"`
	Temperature      float64 `json:"temperature"`
	AvgLogprob       float64 `json:"avg_logprob"`
	CompressionRatio float64 `json:"compression_ratio"`
	NoSpeechProb     float64 `json:"no_speech_prob"`
	Transient        bool    `json:"transient"`
}

Segment represents a segment of transcribed text in the TranscribeResponse.

type TranscribeConfig

type TranscribeConfig struct {
	Model    string
	Language string
	File     string
}

TranscribeConfig is a structure that holds the configuration for the Transcribe method.

type TranscribeOption

type TranscribeOption func(*TranscribeConfig)

TranscribeOption is a function type that allows to set options for the Transcribe method.

func WithFile

func WithFile(file string) TranscribeOption

WithFile sets the file for the Transcribe method.

func WithLanguage

func WithLanguage(lang string) TranscribeOption

WithLanguage sets the language for the Transcribe method.

func WithModel

func WithModel(model string) TranscribeOption

WithModel sets the model for the Transcribe method.

type TranscribeResponse

type TranscribeResponse struct {
	Task     string    `json:"task"`
	Language string    `json:"language"`
	Duration float64   `json:"duration"`
	Segments []Segment `json:"segments"`
	Text     string    `json:"text"`
}

TranscribeResponse represents the response from the Whisper ASR API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL