models

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedFormat = errors.New("sarvam: unsupported audio format")

Functions

func Bool

func Bool(v bool) *bool

func Float

func Float(v float64) *float64

func Int

func Int(v int) *int

func PCM16ToULaw added in v0.3.0

func PCM16ToULaw(pcm []byte) []byte

func ReadAll

func ReadAll(in Input) ([]byte, error)

func ResamplePCM16 added in v0.3.0

func ResamplePCM16(pcm []byte, from, to int) []byte

func String

func String(v string) *string

func ULawToPCM16 added in v0.3.0

func ULawToPCM16(ulaw []byte) []byte

func UnwrapWAV added in v0.3.0

func UnwrapWAV(data []byte) ([]byte, int, error)

func WrapWAV added in v0.3.0

func WrapWAV(pcm []byte, sampleRate int) []byte

Types

type Audio

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

func NewAudio

func NewAudio(data []byte, f Format) *Audio

func (*Audio) Bytes

func (a *Audio) Bytes() []byte

func (*Audio) Duration

func (a *Audio) Duration() time.Duration

func (*Audio) Format

func (a *Audio) Format() Format

func (*Audio) Len

func (a *Audio) Len() int

func (*Audio) PCM16 added in v0.3.0

func (a *Audio) PCM16() ([]byte, int, error)

func (*Audio) Read

func (a *Audio) Read(p []byte) (int, error)

func (*Audio) SampleRate

func (a *Audio) SampleRate() int

func (*Audio) Save

func (a *Audio) Save(path string) error

func (*Audio) WriteTo

func (a *Audio) WriteTo(w io.Writer) (int64, error)

type AudioChunk

type AudioChunk struct {
	Bytes []byte
	Index int
}

type BatchRequest

type BatchRequest struct {
	Files       []Input
	Model       Model
	Mode        Mode
	Language    Language
	Timestamps  bool
	Diarize     bool
	NumSpeakers int
	Keyterms    []string
	InputCodec  string

	CallbackURL   string
	CallbackToken string
}

type ChatChoice added in v0.2.0

type ChatChoice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason string  `json:"finish_reason"`
}

type ChatChunk added in v0.2.0

type ChatChunk struct {
	ID      string            `json:"id"`
	Object  string            `json:"object"`
	Created int64             `json:"created"`
	Model   string            `json:"model"`
	Choices []ChatChunkChoice `json:"choices"`
	Usage   *Usage            `json:"usage"`
}

func (ChatChunk) Content added in v0.2.0

func (c ChatChunk) Content() string

func (ChatChunk) Done added in v0.2.0

func (c ChatChunk) Done() bool

func (ChatChunk) Reasoning added in v0.2.0

func (c ChatChunk) Reasoning() string

type ChatChunkChoice added in v0.2.0

type ChatChunkChoice struct {
	Index        int       `json:"index"`
	Delta        ChatDelta `json:"delta"`
	FinishReason string    `json:"finish_reason"`
}

type ChatDelta added in v0.2.0

type ChatDelta struct {
	Role             Role            `json:"role"`
	Content          string          `json:"content"`
	ReasoningContent string          `json:"reasoning_content"`
	ToolCalls        []ToolCallDelta `json:"tool_calls"`
}

type ChatRequest added in v0.2.0

type ChatRequest struct {
	Model    Model
	Messages []Message

	Temperature      *float64
	TopP             *float64
	MaxTokens        int
	Stop             []string
	N                int
	Seed             *int
	FrequencyPenalty *float64
	PresencePenalty  *float64
	Tools            []Tool
	ToolChoice       any
	ResponseFormat   any

	ReasoningEffort ReasoningEffort
}

type ChatResponse added in v0.2.0

type ChatResponse struct {
	ID      string       `json:"id"`
	Object  string       `json:"object"`
	Created int64        `json:"created"`
	Model   string       `json:"model"`
	Choices []ChatChoice `json:"choices"`
	Usage   *Usage       `json:"usage"`
}

func (*ChatResponse) Content added in v0.2.0

func (r *ChatResponse) Content() string

func (*ChatResponse) FinishReason added in v0.2.0

func (r *ChatResponse) FinishReason() string

func (*ChatResponse) HasToolCalls added in v0.2.0

func (r *ChatResponse) HasToolCalls() bool

func (*ChatResponse) Reasoning added in v0.2.0

func (r *ChatResponse) Reasoning() string

func (*ChatResponse) ToolCalls added in v0.2.0

func (r *ChatResponse) ToolCalls() []ToolCall

type Codec

type Codec string
const (
	CodecMP3   Codec = "mp3"
	CodecWAV   Codec = "wav"
	CodecFLAC  Codec = "flac"
	CodecOpus  Codec = "opus"
	CodecAAC   Codec = "aac"
	CodecPCM16 Codec = "linear16"
	CodecULaw  Codec = "mulaw"
	CodecALaw  Codec = "alaw"
)

type FinalTranscript

type FinalTranscript struct {
	Utterance          int
	Text               string
	Language           Language
	LanguageConfidence float64
	Start              time.Duration
	End                time.Duration
}

type Format

type Format struct {
	Codec      Codec
	SampleRate int
	Bitrate    int
}

func AAC

func AAC(sampleRate, kbps int) Format

func ALaw8000

func ALaw8000() Format

func FLAC

func FLAC(sampleRate int) Format

func MP3

func MP3(sampleRate, kbps int) Format

func Opus

func Opus(sampleRate, kbps int) Format

func PCM16

func PCM16(sampleRate int) Format

func ULaw8000

func ULaw8000() Format

func WAV

func WAV(sampleRate int) Format

func (Format) BitrateParam

func (f Format) BitrateParam() string

func (Format) IsZero

func (f Format) IsZero() bool

func (Format) MIMEType

func (f Format) MIMEType() string

func (Format) String

func (f Format) String() string

type FunctionCall added in v0.2.0

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

func (FunctionCall) ParseArguments added in v0.2.0

func (f FunctionCall) ParseArguments(into any) error

type FunctionDefinition added in v0.2.0

type FunctionDefinition struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters,omitempty"`
	Strict      *bool  `json:"strict,omitempty"`
}

type Input

type Input interface {
	Filename() string
	ContentType() string
	Open() (io.ReadCloser, error)
	Size() int64
	Replayable() bool
	Duration() (time.Duration, bool)
}

func BytesInput

func BytesInput(data []byte, f Format) Input

func FileInput

func FileInput(path string) Input

func ReaderInput

func ReaderInput(r io.Reader, name, ctype string) Input

type Job

type Job struct {
	ID        string
	State     JobState
	Total     int
	Succeeded int
	Failed    int
	Error     string
	Files     []JobFile
}

type JobFile

type JobFile struct {
	Input  string
	Output string
	State  string
	Error  string
}

type JobState

type JobState string
const (
	JobAccepted           JobState = "Accepted"
	JobPending            JobState = "Pending"
	JobRunning            JobState = "Running"
	JobCompleted          JobState = "Completed"
	JobPartiallyCompleted JobState = "PartiallyCompleted"
	JobFailed             JobState = "Failed"
)

func (JobState) Done

func (s JobState) Done() bool

type Language

type Language string
const (
	LangEnglish   Language = "en-IN"
	LangHindi     Language = "hi-IN"
	LangBengali   Language = "bn-IN"
	LangGujarati  Language = "gu-IN"
	LangKannada   Language = "kn-IN"
	LangMalayalam Language = "ml-IN"
	LangMarathi   Language = "mr-IN"
	LangOdia      Language = "od-IN"
	LangPunjabi   Language = "pa-IN"
	LangTamil     Language = "ta-IN"
	LangTelugu    Language = "te-IN"
)

type Message added in v0.2.0

type Message struct {
	Role             Role       `json:"role"`
	Content          string     `json:"content"`
	Name             string     `json:"name,omitempty"`
	ReasoningContent string     `json:"reasoning_content,omitempty"`
	ToolCalls        []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID       string     `json:"tool_call_id,omitempty"`
}

func AssistantMessage added in v0.2.0

func AssistantMessage(content string) Message

func SystemMessage added in v0.2.0

func SystemMessage(content string) Message

func ToolMessage added in v0.2.0

func ToolMessage(callID, content string) Message

func UserMessage added in v0.2.0

func UserMessage(content string) Message

type Mode

type Mode string
const (
	ModeTranscribe Mode = "transcribe"
	ModeTranslate  Mode = "translate"
	ModeVerbatim   Mode = "verbatim"
	ModeTranslit   Mode = "translit"
	ModeCodemix    Mode = "codemix"
)

type Model

type Model string
const (
	ChatSarvam105B              Model = "sarvam-105b"
	ChatSarvam105BConversations Model = "sarvam-105b-conversations"
)
const (
	TTSBulbulV3 Model = "bulbul:v3"
	TTSBulbulV2 Model = "bulbul:v2"
)
const (
	STTSaarasV3         Model = "saaras:v3"
	STTSaarasV4         Model = "saaras:v4"
	STTSaarasV3Realtime Model = "saaras:v3-realtime"
	STTSaarasV4Realtime Model = "saaras:v4-realtime"
)

type PartialTranscript

type PartialTranscript struct {
	Utterance int
	Text      string
	Language  Language
}

type ReasoningEffort added in v0.2.0

type ReasoningEffort string
const (
	ReasoningLow    ReasoningEffort = "low"
	ReasoningMedium ReasoningEffort = "medium"
	ReasoningHigh   ReasoningEffort = "high"
	ReasoningOff    ReasoningEffort = "off"
)

type Role added in v0.2.0

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type SessionEnded

type SessionEnded struct {
	AudioDuration time.Duration
	Utterances    int
}

type SessionStarted

type SessionStarted struct{ RequestID string }

type SpeakerTurn

type SpeakerTurn struct {
	Speaker string
	Text    string
	Start   time.Duration
	End     time.Duration
}

type SpeechEnded

type SpeechEnded struct {
	Utterance  int
	Confidence float64
}

type SpeechRequest

type SpeechRequest struct {
	Model    Model
	Voice    string
	Text     string
	Language Language
	Format   Format

	Speed       *float64
	Pitch       *float64
	Loudness    *float64
	Temperature *float64
	Preprocess  *bool
	Dictionary  string

	MinBufferSize  int
	MaxChunkLength int
	SentenceLimit  int
}

type SpeechStarted

type SpeechStarted struct {
	Utterance  int
	Confidence float64
}

type StreamType

type StreamType string
const (
	StreamFast      StreamType = "fast"
	StreamBalanced  StreamType = "balanced"
	StreamSimulated StreamType = "simulated"
)

type Tool added in v0.2.0

type Tool struct {
	Type     string             `json:"type"`
	Function FunctionDefinition `json:"function"`
}

func FunctionTool added in v0.2.0

func FunctionTool(name, description string, parameters any) Tool

type ToolCall added in v0.2.0

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

type ToolCallDelta added in v0.2.0

type ToolCallDelta struct {
	Index    int    `json:"index"`
	ID       string `json:"id"`
	Type     string `json:"type"`
	Function struct {
		Name      string `json:"name"`
		Arguments string `json:"arguments"`
	} `json:"function"`
}

type TranscriptionEvent

type TranscriptionEvent interface {
	// contains filtered or unexported methods
}

type TranscriptionRequest

type TranscriptionRequest struct {
	Model      Model
	Audio      Input
	Language   Language
	Mode       Mode
	Timestamps bool
	Keyterms   []string
	InputCodec string
}

type TranscriptionResult

type TranscriptionResult struct {
	RequestID           string
	Text                string
	Language            Language
	LanguageProbability float64
	Words               []Word
}

func (*TranscriptionResult) SRT

func (r *TranscriptionResult) SRT() string

func (*TranscriptionResult) SpeakerTurns

func (r *TranscriptionResult) SpeakerTurns() []SpeakerTurn

func (*TranscriptionResult) VTT

func (r *TranscriptionResult) VTT() string

type TranscriptionStreamRequest

type TranscriptionStreamRequest struct {
	Model       Model
	Language    Language
	Mode        Mode
	InputFormat Format
	StreamType  StreamType
	Prompt      string
	Timestamps  bool

	ManualEndpointing bool
	VADThreshold      *float64
	SilenceDuration   time.Duration
	MinSpeechDuration time.Duration
}

type Usage added in v0.2.0

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type Word

type Word struct {
	Text    string
	Start   time.Duration
	End     time.Duration
	Speaker string
}

Jump to

Keyboard shortcuts

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