types

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 2 Imported by: 4

Documentation

Overview

Package types provides core type definitions, constants, and interfaces used throughout the SaluteSpeech API client library. It defines content types, error types, logger interfaces, and other shared types.

Index

Constants

View Source
const (
	DefaultBaseURL            = "https://smartspeech.sber.ru/rest/v1/"
	DefaultOAuthURL           = "https://ngw.devices.sberbank.ru:9443/api/v2/oauth"
	DefaultUploadURL          = "https://smartspeech.sber.ru/rest/v1/data:upload"
	DefaultSynthesizeURL      = "https://smartspeech.sber.ru/rest/v1/text:async_synthesize"
	DefaultTaskURL            = "https://smartspeech.sber.ru/rest/v1/task:get"
	DefaultDownloadURL        = "https://smartspeech.sber.ru/rest/v1/data:download"
	DefaultResultURL          = "https://smartspeech.sber.ru/rest/v1/speech:recognition_result"
	DefaultSyncRecognitionURL = "https://smartspeech.sber.ru/rest/v1/speech:recognize"
	DefaultSyncSynthesisURL   = "https://smartspeech.sber.ru/rest/v1/text:synthesize"
)

Default URLs

View Source
const (
	MinFileSize        = 400
	MaxSyncFileSize    = 2 * 1024 * 1024 // 2 MB
	MaxTextLength      = 4000
	MaxSampleRate      = 96000
	MinSampleRate      = 8000
	MaxChannelsCount   = 2
	MinChannelsCount   = 1
	MaxHypothesesCount = 5
	MaxUploadFileSize  = 20 * 1024 * 1024 // 20 MB
)

Limits

View Source
const (
	DefaultTimeout       = 30 * time.Second
	DefaultUploadTimeout = 5 * time.Minute
	DefaultAPITimeout    = 60 * time.Second
	DefaultPollInterval  = 2 * time.Second
	DefaultWaitTimeout   = 10 * time.Minute
	DefaultRefreshMargin = 1 * time.Minute
	DefaultMinRefreshInt = 30 * time.Second
)

Timeouts

Variables

View Source
var (
	// Authentication errors
	ErrAuthKeyRequired      = errors.New("auth key is required")
	ErrScopeRequired        = errors.New("scope is required")
	ErrTokenManagerRequired = errors.New("token manager is required")
	ErrInvalidAuthHeader    = errors.New("invalid authorization header")

	// Request errors
	ErrEmptyFileData         = errors.New("empty file data")
	ErrInvalidContentType    = errors.New("invalid content type")
	ErrFileTooSmall          = errors.New("file too small")
	ErrEmptyTaskID           = errors.New("empty task id")
	ErrRequestNil            = errors.New("request is nil")
	ErrRequestFileIDRequired = errors.New("request_file_id is required")
	ErrOptionsRequired       = errors.New("options is required")
	ErrEmptyText             = errors.New("text is empty")
	ErrFileTooLarge          = errors.New("file too large")

	// API errors
	ErrUnauthorized    = errors.New("unauthorized")
	ErrTooManyRequests = errors.New("too many requests")
	ErrServerError     = errors.New("server error")
	ErrBadRequest      = errors.New("bad request")
)

Common errors

Functions

This section is empty.

Types

type ContentType

type ContentType string

ContentType represents audio and content MIME types supported by the SaluteSpeech API. These types are used to specify the format of audio files for recognition, text content for synthesis, and expected response formats.

const (
	// ContentAudioMPEG represents MP3 audio format (audio/mpeg)
	ContentAudioMPEG ContentType = "audio/mpeg"

	// ContentAudioFLAC represents FLAC (Free Lossless Audio Codec) format (audio/flac)
	ContentAudioFLAC ContentType = "audio/flac"

	// ContentAudioOGGOpus represents Ogg container with Opus codec (audio/ogg;codecs=opus)
	ContentAudioOGGOpus ContentType = "audio/ogg;codecs=opus"

	// ContentAudioPCM8k16bit represents raw PCM audio at 8kHz sampling rate, 16-bit depth
	ContentAudioPCM8k16bit ContentType = "audio/x-pcm;bit=16;rate=8000"

	// ContentAudioPCM16k16bit represents raw PCM audio at 16kHz sampling rate, 16-bit depth
	// This is the recommended format for speech recognition
	ContentAudioPCM16k16bit ContentType = "audio/x-pcm;bit=16;rate=16000"

	// ContentAudioPCMA8k represents A-law encoded audio at 8kHz sampling rate
	ContentAudioPCMA8k ContentType = "audio/pcma;rate=8000"

	// ContentAudioPCMA16k represents A-law encoded audio at 16kHz sampling rate
	ContentAudioPCMA16k ContentType = "audio/pcma;rate=16000"

	// ContentAudioPCMU8k represents μ-law encoded audio at 8kHz sampling rate
	ContentAudioPCMU8k ContentType = "audio/pcmu;rate=8000"

	// ContentAudioPCMU16k represents μ-law encoded audio at 16kHz sampling rate
	ContentAudioPCMU16k ContentType = "audio/pcmu;rate=16000"

	// ContentTextPlain represents plain text content (text/plain)
	// Used for text uploads in synthesis tasks
	ContentTextPlain ContentType = "text/plain"

	// ContentApplicationSSML represents SSML (Speech Synthesis Markup Language) content
	// Used for advanced speech synthesis with pronunciation control
	ContentApplicationSSML ContentType = "application/ssml"
)

func (ContentType) IsValid

func (ct ContentType) IsValid() bool

IsValid checks if the content type is supported by the SaluteSpeech API. It returns true for all predefined content type constants, false for any other value. This is useful for validating user input and ensuring compatibility with API endpoints.

type Logger

type Logger interface {
	Debug(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Warn(msg string, keysAndValues ...interface{})
	Error(msg string, keysAndValues ...interface{})
}

Logger interface for logging

type NoopLogger

type NoopLogger struct{}

NoopLogger implements Logger with no operations

func (NoopLogger) Debug

func (n NoopLogger) Debug(string, ...interface{})

func (NoopLogger) Error

func (n NoopLogger) Error(string, ...interface{})

func (NoopLogger) Info

func (n NoopLogger) Info(string, ...interface{})

func (NoopLogger) Warn

func (n NoopLogger) Warn(string, ...interface{})

type Scope

type Scope string

Scope defines API access scope

const (
	ScopeSaluteSpeechPers Scope = "SALUTE_SPEECH_PERS"
	ScopeSaluteSpeechCorp Scope = "SALUTE_SPEECH_CORP"
	ScopeSaluteSpeechB2B  Scope = "SALUTE_SPEECH_B2B"
	ScopeSberSpeech       Scope = "SBER_SPEECH"
	ScopeGigaChatAPIPers  Scope = "GIGACHAT_API_PERS"
)

type TaskStatus

type TaskStatus string

TaskStatus represents task status

const (
	StatusNEW        TaskStatus = "NEW"
	StatusRUNNING    TaskStatus = "RUNNING"
	StatusPROCESSING TaskStatus = "PROCESSING"
	StatusCANCELED   TaskStatus = "CANCELED"
	StatusDONE       TaskStatus = "DONE"
	StatusERROR      TaskStatus = "ERROR"
)

func (TaskStatus) IsTerminal

func (s TaskStatus) IsTerminal() bool

IsTerminal checks if task status is terminal

func (TaskStatus) IsValid

func (s TaskStatus) IsValid() bool

IsValid checks if task status is valid

type TaskStatusResponse

type TaskStatusResponse struct {
	Status int `json:"status"`
	Result struct {
		ID        string     `json:"id"`
		CreatedAt time.Time  `json:"created_at"`
		UpdatedAt time.Time  `json:"updated_at"`
		Status    TaskStatus `json:"status"`
	} `json:"result"`
}

TaskStatusResponse represents task status API response

type Token

type Token struct {
	Value     string
	ExpiresAt time.Time
}

Token represents OAuth token

func (*Token) IsValid

func (t *Token) IsValid(margin time.Duration) bool

IsValid checks if token is valid with given margin

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
}

TokenResponse represents OAuth token response

type Voice

type Voice string

Voice represents synthesis voice

const (
	VoiceOst24000     Voice = "Ost_24000"
	VoiceAida24000    Voice = "Aida_24000"
	VoiceFilipp24000  Voice = "Filipp_24000"
	VoiceJasmine24000 Voice = "Jasmine_24000"
	VoiceMay24000     Voice = "May_24000"
	VoiceErmil24000   Voice = "Ermil_24000"
	VoiceMay8000      Voice = "May_8000"
	VoiceOst8000      Voice = "Ost_8000"
	VoiceJoy24000     Voice = "Joy_24000"
	VoiceNick24000    Voice = "Nick_24000"
	VoiceAigerim24000 Voice = "Aigerim_24000"
	VoiceNazira24000  Voice = "Nazira_24000"
)

Jump to

Keyboard shortcuts

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