fish

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 14 Imported by: 1 module, 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

Overview

Package fish is a streaming text-to-speech service backed by Fish Audio. It requests PCM output so raw audio streams straight downstream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// APIKey is the Fish Audio API key. Required.
	APIKey string `validate:"required"`
	// BaseURL overrides the API base; empty uses the hosted API.
	BaseURL string
	// Model is the backend model, sent as the "model" request header; empty uses
	// a current default.
	Model string
	// ReferenceID selects a voice model (a library or cloned voice). Recommended;
	// empty uses the model's default voice.
	ReferenceID string
	// SampleRate is the PCM output rate; empty uses 24 kHz. Supported: 8000,
	// 16000, 24000, 32000, 44100.
	SampleRate int
	// Speed scales the speaking rate; nil leaves it at the default. It seeds
	// the prosody_speed setting.
	Speed *float64
	// Settings overrides the starting settings, field by field: a field it
	// does not give keeps its value, and one given no value (settings.Cleared)
	// is left out of the request. It wins over the fields above. Nil keeps
	// them: latency "balanced", normalization on, prosody speed 1.0 and volume
	// 0 dB, and Fish's own defaults for the rest.
	Settings *TTSSettings
}

Config configures the Fish Audio TTS service.

func (Config) Validate

func (c Config) Validate() error

Validate reports whether the configuration is usable.

type S2ExpressionAdapter added in v1.0.0

type S2ExpressionAdapter struct {
	expressive.BaseExpressionAdapter
}

S2ExpressionAdapter formats expression tags as Fish Audio S2 bracket tags.

Delivery and sounds are both tags, such as [excited] or [laughing], written in free text: the terms listed are Fish Audio's S2 emotion reference, and others described in a few words work too. A tag applies within the input it is sent in, so each sentence states its delivery from its start. There is no tag for the voice's baseline, so a return to it writes none. Slow and fast are written as [speaking slowly] and [speaking quickly], and since a pace lasts until another tag changes it, a [normal pace] tag ends them, within a sentence or at the end of one. Emphasis is an [emphasis] tag before the stressed words, and a pause is a break or a long break, which is approximate.

func (S2ExpressionAdapter) Capabilities added in v1.0.0

Capabilities implements expressive.ExpressionAdapter: free-text tags, emphasis and approximate pauses.

func (S2ExpressionAdapter) FormatEnd added in v1.0.0

func (S2ExpressionAdapter) FormatEnd(delivery []string) string

FormatEnd implements expressive.ExpressionAdapter: it sets the pace back after a request that ends in a speed delivery.

func (S2ExpressionAdapter) FormatPause added in v1.0.0

func (S2ExpressionAdapter) FormatPause(durationMS int) string

FormatPause implements expressive.ExpressionAdapter: a break under a second, otherwise a long break.

func (S2ExpressionAdapter) FormatSound added in v1.0.0

func (S2ExpressionAdapter) FormatSound(name string) string

FormatSound implements expressive.ExpressionAdapter: a tag.

func (S2ExpressionAdapter) FormatText added in v1.0.0

func (S2ExpressionAdapter) FormatText(text string, delivery, previousDelivery []string) string

FormatText implements expressive.ExpressionAdapter: it prefixes tags where the delivery changes, and emphasis before stressed words.

type TTSService added in v1.0.0

type TTSService struct {
	*tts.Base
}

TTSService is the Fish Audio text-to-speech service NewTTS builds.

func NewTTS

func NewTTS(cfg Config) *TTSService

NewTTS builds a Fish Audio TTS service.

type TTSSettings added in v1.2.0

type TTSSettings struct {
	settings.TTS

	// Latency is the latency mode: "normal" or "balanced".
	Latency settings.Opt[string] `settings:"latency"`
	// Normalize normalizes the text before synthesis.
	Normalize settings.Opt[bool] `settings:"normalize"`
	// Temperature controls randomness in speech generation (0.0 to 1.0).
	Temperature settings.Opt[float64] `settings:"temperature"`
	// TopP controls diversity through nucleus sampling (0.0 to 1.0).
	TopP settings.Opt[float64] `settings:"top_p"`
	// ProsodySpeed multiplies the speaking rate (0.5 to 2.0).
	ProsodySpeed settings.Opt[float64] `settings:"prosody_speed"`
	// ProsodyVolume adjusts the volume in dB (-20 to 20).
	ProsodyVolume settings.Opt[int] `settings:"prosody_volume"`
	// ProsodyNormalizeLoudness normalizes the output loudness for a more
	// consistent perceived volume. It applies to the S2 family and drama-3.
	ProsodyNormalizeLoudness settings.Opt[bool] `settings:"prosody_normalize_loudness"`
	// ChunkLength is the text segment size Fish processes (100 to 300).
	ChunkLength settings.Opt[int] `settings:"chunk_length"`
	// MinChunkLength is the minimum number of characters before Fish splits
	// into a new chunk (0 to 100).
	MinChunkLength settings.Opt[int] `settings:"min_chunk_length"`
	// ConditionOnPreviousChunks uses the audio already generated as context,
	// for a voice consistent across chunks.
	ConditionOnPreviousChunks settings.Opt[bool] `settings:"condition_on_previous_chunks"`
}

TTSSettings is the part of the Fish Audio synthesis configuration that can change while the pipeline runs. Every request carries all of it, so a change applies from the next sentence.

The voice is the reference id of a library or cloned voice. The language is a BCP-47 tag of the text, such as "en" or "es-MX": Fish uses it only to spell out numbers, dates, units and symbols, and it does not change the voice. Unset detects the language of each chunk.

func (*TTSSettings) FromMap added in v1.2.0

func (s *TTSSettings) FromMap(values map[string]any) error

FromMap fills the settings from plain names and values, implementing settings.Mapper. A nested prosody object, the shape Fish's own requests carry it in, is read into the prosody settings; a key it leaves out stays unset, and a flat setting given alongside wins.

Jump to

Keyboard shortcuts

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