Documentation
¶
Overview ¶
Package espeak implements C bindings for the Espeak voice synthesizer. It also provides Go wrappers around espeak's api that allow for creation of custom text synthesis functions.
Index ¶
- Variables
- func Cancel() error
- func ErrFromCode(code C.espeak_ERROR) error
- func GenSamples(text string, voice *Voice, params *Parameters) ([]int16, error)
- func Init(output AudioOutput, bufferLength int, path *string, options InitOption) (uintptr, int32, error)
- func IsPlaying() bool
- func SampleRate() int32
- func SetSynthCallback(ptr unsafe.Pointer)
- func SetVoiceByName(name string) error
- func SetVoiceByProps(v *Voice) error
- func Synchronize() error
- func Synth(text string, flags FlagType, startPos, endPos uint32, posType PositionType, ...) error
- func Terminate() error
- func TextToSpeech(text string, voice *Voice, outfile string, params *Parameters) (uint64, error)
- type Age
- type AudioOutput
- type Capitals
- type FlagType
- type Gender
- type InitOption
- type LibError
- type Option
- type Parameters
- func (p *Parameters) PunctuationList() string
- func (p *Parameters) SetPunctuationList(chars string)
- func (p *Parameters) SetVoiceParams() error
- func (p *Parameters) WithAnnounceCapitals(cap Capitals) *Parameters
- func (p *Parameters) WithAnnouncePunctuation(punct PunctType) *Parameters
- func (p *Parameters) WithDir(path string) *Parameters
- func (p *Parameters) WithPitch(pitch int) *Parameters
- func (p *Parameters) WithRange(rng int) *Parameters
- func (p *Parameters) WithRate(rate int) *Parameters
- func (p *Parameters) WithVolume(volume int) *Parameters
- func (p *Parameters) WithWordGap(wg int) *Parameters
- type PositionType
- type PunctType
- type Variant
- type Voice
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultVoice = ENUSMale ENUSMale = &Voice{Name: "english-us", Languages: "en-us", Identifier: "en-us", Gender: Male} ESSpainMale = &Voice{Name: "spanish", Languages: "es", Identifier: "europe/es", Gender: Male} ESLatinMale = &Voice{Name: "spanish-latin-am", Languages: "es-la", Identifier: "es-la", Gender: Male} FRFranceMale = &Voice{Name: "french", Languages: "fr-fr", Identifier: "fr", Gender: Male} )
Default voices.
var ( // EErrOK espeak return for not-really-an-error. EErrOK = &LibError{0, "OK"} // EErrInternal espeak return for internal error EErrInternal = &LibError{-1, "Internal error"} // EErrBufferFull espeak buffer full error. EErrBufferFull = &LibError{1, "Buffer full"} // EErrNotFound espeak not found error. EErrNotFound = &LibError{2, "Not found"} // ErrEmptyText text is empty. ErrEmptyText = errors.New("text is empty") // ErrUnknown unknown error code. ErrUnknown = errors.New("unknown error code") // ErrAlreadyInitialized espeak already initialized. ErrAlreadyInitialized = errors.New("espeak already initialized") // ErrNotInitialized espeak not initialized (call Init). ErrNotInitialized = errors.New("espeak not initialized (call Init)") )
Errors
var DefaultParameters = &Parameters{ Rate: 175, Volume: 100, Pitch: 50, Range: 50, AnnouncePunctuation: PunctNone, AnnounceCapitals: CapitalNone, WordGap: 10, Dir: os.TempDir(), }
DefaultParameters for voice modulation.
Functions ¶
func Cancel ¶ added in v0.1.8
func Cancel() error
Cancel wrapper around espeak_Cancel. Stop immediately synthesis and audio output of the current text. When this function returns, the audio output is fully stopped and the synthesizer is ready to synthesize a new message.
func ErrFromCode ¶ added in v0.1.8
func ErrFromCode(code C.espeak_ERROR) error
ErrFromCode get a Go error from an espeak_ERROR.
func GenSamples ¶ added in v0.1.10
func GenSamples(text string, voice *Voice, params *Parameters) ([]int16, error)
GenSamples generates a []int16 sample slice containing the data of text, using voice, modified by params. If params is nil, default parameters are used.
func Init ¶ added in v0.1.8
func Init( output AudioOutput, bufferLength int, path *string, options InitOption, ) (uintptr, int32, error)
Init wrapper around espeak_Initialize. Returns a uintptr id which the address of the data block (T: *[]int16) acted on, and the sample rate used.
- output AudioOutput type.
- bufferLength length in mS of sound buffers passed to the SynthCallback function. If 0 gives a default of 200mS. Only used for output==Retrieval and output == Synchronous.
- path: the directory which contains the espeak-data directory.
- options: InitOption to use.
func IsPlaying ¶ added in v0.1.8
func IsPlaying() bool
IsPlaying returns whether audio is being played.
func SampleRate ¶ added in v0.1.10
func SampleRate() int32
SampleRate return the produced sample rate.
func SetSynthCallback ¶ added in v0.1.8
SetSynthCallback to the unsafe.Pointer passed. The underlying C object has to be a a function of signature
int (t_espeak_callback)(short*, int, espeak_EVENT*)
func SetVoiceByName ¶ added in v0.1.8
SetVoiceByName wrapper around espeak_SetVoiceByName.
func SetVoiceByProps ¶ added in v0.1.8
SetVoiceByProps wrapper around espeak_SetVoiceByProperties. An *Voice is used to pass criteria to select a voice.
func Synchronize ¶ added in v0.1.8
func Synchronize() error
Synchronize wrapper around espeak_Synchronize.
func Synth ¶ added in v0.1.8
func Synth( text string, flags FlagType, startPos, endPos uint32, posType PositionType, uniqueIdent *uint64, userData unsafe.Pointer, ) error
Synth wrapper around espeak_Synth.
- text: text to synthezise.
- flags: flag values to pass.
- startPos, endPos: start and end position in the text where speaking starts and ends. If endPos is zero indicates no end position.
- posType: PositionType to use.
- uniqueIdent: This must be either NULL, or point to an integer variable to which eSpeak writes a message identifier number. eSpeak includes this number in espeak_EVENT messages which are the result of this call of espeak_Synth().
- userData: a pointer (or NULL) which will be passed to the callback function in espeak_EVENT messages.
func Terminate ¶ added in v0.1.8
func Terminate() error
Terminate closes the espeak connection. It's up to the caller to call this and terminate the function.
func TextToSpeech ¶
TextToSpeech reproduces text, using voice, modified by params. If params is nil, default parameters are used. If outfile is an empty string or "play", the audio is spoken to the system default's audio output; otherwise is appended with .wav and saved to params.Dir/outfile[.wav]. Returns the number of samples written to file, if any.
Example ¶
espeak.TextToSpeech("Hello world!", espeak.DefaultVoice, "play", nil) // or set an outfile name to save it // TextToSpeech("Hello world!", ENUSFemale, "hello-world.wav", nil)
Example (CustomVoice) ¶
ExampleTextToSpeech_second show usage with a non-default voice.
// output of // ~$ espeak --voices=el // Pty Language Age/Gender VoiceName File Other Languages // 5 el M greek europe/el // 7 el M greek-mbrola-1 mb/mb-gr2 greek := espeak.Voice{ Languages: "el", Gender: espeak.Male, Name: "greek", Identifier: "europe/el", } espeak.TextToSpeech("Γειά σου Κόσμε!", &greek, "play", nil)
Types ¶
type AudioOutput ¶ added in v0.1.8
type AudioOutput uint8
AudioOutput type.
const ( // Playback plays the audio data, supplies events to the calling program. Playback AudioOutput = iota + 1 // Retrieval supplies audio data and events to the calling program. Retrieval // Synchronous as Retrieval but doesn't return until synthesis is completed. Synchronous // SynchPlayback synchronous playback. SynchPlayback )
type Capitals ¶
type Capitals int
Capitals setting to announce capital letters by.
const ( // CapitalNone announce no capitals. CapitalNone Capitals = iota // CapitalSoundIcon distinctive sound for capitals. CapitalSoundIcon // CapitalSpelling spells out "Capital A" for each capital. CapitalSpelling // CapitalPitchRaise uses a different pitch for capital letters. CapitalPitchRaise )
type FlagType ¶ added in v0.1.8
type FlagType uint16
FlagType one-to-one mapping to the espeak flags.
const ( // CharsAuto 8 bit or UTF8 (this is the default). CharsAuto FlagType = iota // CharsUTF8 utf-8 encoding. CharsUTF8 // Chars8Bit the 8 bit ISO-8859 character set for the particular language. Chars8Bit // CharsWChar Wide characters (wchar_t). CharsWChar // Chars16Bit 16 bit characters. Chars16Bit // SSML Elements within < > are treated as SSML elements, or if not // recognised are ignored. SSML FlagType = 0x10 // Phonemes Text within [[ ]] is treated as phonemes codes (in espeak's // Hirshenbaum encoding). Phonemes FlagType = 0x100 // EndPause if set then a sentence pause is added at the end of the text. // If not set then this pause is suppressed. EndPause FlagType = 0x1000 )
type Gender ¶
type Gender int
Gender voice gender.
func (Gender) MarshalJSON ¶ added in v0.1.8
MarshalJSON marshals the Gender into a string.
func (*Gender) UnmarshalJSON ¶ added in v0.1.8
UnmarshalJSON implements the JSON.Unmarshaler interface.
type InitOption ¶ added in v0.1.8
type InitOption uint8
InitOption initialization options. Beware only PhonemeEvents and PhonemeIPA are the only ones that belong to espeak.
const ( // PhonemeEvents allow espeakEVENT_PHONEME events. PhonemeEvents InitOption = 1 << iota // PhonemeIPA espeak events give IPA phoneme names, not eSpeak phoneme names. PhonemeIPA // UseMbrola allow usage of mbrola voices, excluded by default. This is not an // espeak option. UseMbrola )
type LibError ¶ added in v0.1.4
type LibError struct {
// contains filtered or unexported fields
}
LibError analog to espeak_ERROR.
type Option ¶
type Option func(*Parameters)
Option parameter creatien function.
func WithAnnounceCapitals ¶
WithAnnounceCapitals cap.
func WithAnnouncePunctuation ¶
WithAnnouncePunctuation punct.
type Parameters ¶
type Parameters struct { // Rate speaking speed in word per minute. Values 80 to 450. Default 175. Rate int // Volume in range 0-200 or more. // 0=silence, 100=normal full volume, greater values may // produce amplitude compression or distortion. Default 100. Volume int // Pitch base pitch. Range 0-100. Default 50 (normal). Pitch int // Range pitch range, range 0-100. 0-monotone, 50=normal. Default 50 (normal). Range int // AnnouncePunctuation settings. See PunctType for details. Default None (0). AnnouncePunctuation PunctType // AnnounceCapitals settings. See Capitals for details. Default None (0). AnnounceCapitals Capitals // WordGap pause between words, units of 10mS (at the default speed). WordGap int // Dir directory path to save .wav files. Default os.TempDir() Dir string // contains filtered or unexported fields }
Parameters espeak voice parameters.
func NewParameters ¶
func NewParameters(opts ...Option) *Parameters
NewParameters returns *DefaultParameters modified by opts.
func (*Parameters) PunctuationList ¶
func (p *Parameters) PunctuationList() string
PunctuationList returns the list of punctuation characters (if any).
func (*Parameters) SetPunctuationList ¶
func (p *Parameters) SetPunctuationList(chars string)
SetPunctuationList sets the list of punctuation characters.
func (*Parameters) SetVoiceParams ¶ added in v0.1.8
func (p *Parameters) SetVoiceParams() error
SetVoiceParams calls espeak_SetParameter for each of the *Parameters fields.
func (*Parameters) WithAnnounceCapitals ¶ added in v0.1.4
func (p *Parameters) WithAnnounceCapitals(cap Capitals) *Parameters
WithAnnounceCapitals cap.
func (*Parameters) WithAnnouncePunctuation ¶ added in v0.1.4
func (p *Parameters) WithAnnouncePunctuation(punct PunctType) *Parameters
WithAnnouncePunctuation punct.
func (*Parameters) WithDir ¶ added in v0.1.4
func (p *Parameters) WithDir(path string) *Parameters
WithDir path.
func (*Parameters) WithPitch ¶ added in v0.1.4
func (p *Parameters) WithPitch(pitch int) *Parameters
WithPitch pitch.
func (*Parameters) WithRange ¶ added in v0.1.4
func (p *Parameters) WithRange(rng int) *Parameters
WithRange rng.
func (*Parameters) WithRate ¶ added in v0.1.4
func (p *Parameters) WithRate(rate int) *Parameters
WithRate rate.
func (*Parameters) WithVolume ¶ added in v0.1.4
func (p *Parameters) WithVolume(volume int) *Parameters
WithVolume volume.
func (*Parameters) WithWordGap ¶ added in v0.1.4
func (p *Parameters) WithWordGap(wg int) *Parameters
WithWordGap wg.
type PositionType ¶ added in v0.1.8
type PositionType uint8
PositionType determines whether "position" is a number of characters, words, or sentences.
const ( // Character position type. Character PositionType = iota + 1 // Word position type. Word // Sentence position type. Sentence )
type Variant ¶
type Variant int
Variant after a list of candidates is produced, scored and sorted, "variant" is used to index that list and choose a voice. variant=0 takes the top voice (i.e. best match). variant=1 takes the next voice, etc
type Voice ¶
type Voice struct { Name string `json:"name,omitempty"` Languages string `json:"languages,omitempty"` Identifier string `json:"identifier,omitempty"` Gender Gender `json:"gender,omitempty"` Age Age Variant Variant }
Voice analogous to C.espeak_VOICE. New voices can be created as long as they're listed in "espeak --voices=<lang>".
func ListVoices ¶ added in v0.1.8
ListVoices reads the voice files from espeak-data/voices and returns them in a []*Voice object. If spec is nil, all available voices are listed. If spec is given, then only the voices which are compatible with the spec are listed, and they are listed in preference order. Init must have been called.
func VoiceFromSpec ¶ added in v0.1.8
VoiceFromSpec returns a random Voice from the group of voices that matches spec. Is spec is nil, returns a random voice.
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
basic-usage
command
|
|
custom-tts
command
|
|
demo
command
|
|
Package native has espeak native C implementation (called by Go) to synthesize audio or write to .wav.
|
Package native has espeak native C implementation (called by Go) to synthesize audio or write to .wav. |
Package wav implements basic utilities for writing .wav files.
|
Package wav implements basic utilities for writing .wav files. |