Documentation ¶
Overview ¶
Package espeak provides bindings for eSpeak <http://espeak.sf.net>.
Please note that functions in this package should only be called from one goroutine at a time as libespeak uses static variables for most of its returned values.
Index ¶
- Constants
- Variables
- func Cancel() error
- func Initialize(output AudioOutput, buflength int, path string, options int) (sampleRate int, err error)
- func Pitch() int
- func Range() int
- func Rate() int
- func SetPitch(percent int) error
- func SetRange(percent int) error
- func SetRate(wpm int) error
- func SetSynthCallback(f func(wav []int16, events []Event) (stop bool))
- func SetURICallback(f func(uri, base string) (replaceWithText bool))
- func SetVoiceByName(name string) error
- func SetVoiceByProperties(name, language string, gender Gender, age uint8, variant int) error
- func SetVolume(percent int) error
- func Synchronize() error
- func Synth(text string, position uint, positionType PositionType, endPosition, flags uint, ...) error
- func TextToPhonemes(text string, phonemeMode PhonemeMode, ipa bool) (phonemes, remaining string)
- func Volume() int
- type AudioOutput
- type BaseEvent
- type EndEvent
- type Event
- type Gender
- type ListTerminatedEvent
- type MarkEvent
- type MsgTerminatedEvent
- type PhonemeEvent
- type PhonemeMode
- type PlayEvent
- type PositionType
- type SampleRateEvent
- type SentenceEvent
- type Voice
- type WordEvent
Constants ¶
const ( // PLAYBACK mode: plays the audio data, supplies events to the calling // program. AudioOutputPlayback = AudioOutput(C.AUDIO_OUTPUT_PLAYBACK) // RETRIEVAL mode: supplies audio data and events to the calling // program. AudioOutputRetrieval = AudioOutput(C.AUDIO_OUTPUT_RETRIEVAL) // SYNCHRONOUS mode: as RETRIEVAL but doesn't return until synthesis is // completed. AudioOutputSynchronous = AudioOutput(C.AUDIO_OUTPUT_SYNCHRONOUS) // Synchronous playback. AudioOutputSynchPlayback = AudioOutput(C.AUDIO_OUTPUT_SYNCH_PLAYBACK) )
const ( InitializePhonemeEvents = 1 << 0 InitializePhonemeIPA = 1 << 1 InitializeDontExit = 1 << 15 )
const ( PosCharacter = PositionType(C.POS_CHARACTER) PosWord = PositionType(C.POS_WORD) PosSentence = PositionType(C.POS_SENTENCE) )
const ( SynthSSML = uint(C.espeakSSML) SynthPhonemes = uint(C.espeakPHONEMES) SynthEndPause = uint(C.espeakENDPAUSE) )
Variables ¶
Functions ¶
func Initialize ¶
func Initialize(output AudioOutput, buflength int, path string, options int) (sampleRate int, err error)
Initialize must be called before any synthesis functions are called.
output: The audio data can either be played by eSpeak or passed back by the
argument to the SetSynthCallback function.
buflength: The length in milliseconds of sound buffers passed to the
argument to the SetSynthCallback functon. 0 gives the default value of 200ms. This paramater is only used for AudioOutputRetrieval and AudioOutputSynchronous modes.
path: The directory which contains the espeak-data directory, or an empty
string for the default location.
options: These may be OR'd together:
InitializePhonemeEvents: Allow espeak.PhonemeEvent events. InitializePhonemeIPA: espeak.PhonemeEvent events give IPA phoneme names, not eSpeak phoneme names. InitializeDontExit: Don't exit if espeak-data is not found. (used for --help)
Returns: sample rate in Hz, or ErrInternalError.
func SetSynthCallback ¶
func SetURICallback ¶
func SetVoiceByName ¶
Searches for a voice with a matching "name" field. Language is not considered.
func SetVoiceByProperties ¶
Sets the voice to one that matches the arguments.
name: An empty string or a voice name. language: An empty string or a single language string (with optional
dialect), eg. "en-uk" or "en".
gender: NoGender (any) or Male/Female. age: 0 or an age in years. variant: The index in the slice that ListVoicesByProperties would return for
the same arguments. 0 for the best match.
func Synchronize ¶
func Synchronize() error
func Synth ¶
func Synth(text string, position uint, positionType PositionType, endPosition, flags uint, uniqueIdentifier *uint, userData interface{}) error
Synthesize speech for the specified text. The speech sound data is passed to the calling program in buffers by means of the callback function specified by espeak.SetSynthCallback. The command is asynchronous: it is internally buffered and returns as soon as possible. If espeak.Initialize was previously called with AudioOutputPlayback as argument, the sound data are played by eSpeak.
text: The text to be spoken.
position: The position in the text where speaking starts. Zero indicates
speak from the start of the text.
positionType: Determines whether "position" is a number of characters,
words, or sentences.
endPosition: If set, this gives a character position at which speaking will
stop. A value of zero indicates no end position.
flags: These may be OR'd together:
SynthSSML Elements within < > are treated as SSML elements, or if not recognised are ignored. SynthPhonemes Text within [[ ]] is treated as phonemes codes (in espeak's Hirshenbaum encoding). SynthEndPause If set then a sentence pause is added at the end of the text. If not set then this pause is suppressed.
uniqueIdentifier: an integer variable to which eSpeak writes a message
identifier number, or nil. eSpeak includes this number in Event messages which are the result of this call
userData: an interface{} or nil, which will be passed to the callback
function in Event messages.
Errors:
ErrBufferFull: the command cannot be buffered; you may try after a while to call the function again. ErrInternalError.
func TextToPhonemes ¶
func TextToPhonemes(text string, phonemeMode PhonemeMode, ipa bool) (phonemes, remaining string)
TextToPhonemes translates text into phonemes. Call SetVoiceByName() first, to select a language.
It returns a string which contains the phonemes for the text up to end of a sentence, or comma, semicolon, colon, or similar punctuation, as well as a string containing the remaining characters.
Types ¶
type AudioOutput ¶
type AudioOutput C.espeak_AUDIO_OUTPUT
type ListTerminatedEvent ¶
type ListTerminatedEvent struct {
BaseEvent
}
Retrieval mode: terminates the event list.
type PhonemeEvent ¶
Phoneme, if enabled in espeak.Initialize()
type PhonemeMode ¶
type PhonemeMode int
const ( PhonemeOnly PhonemeMode = 0 // just phonemes PhonemeTies PhonemeMode = 1 // include ties (U+0361) for multi-letter names PhonemeZWJ PhonemeMode = 2 // include zero-width joiners for phoneme names of more than one letter PhonemeUnderscore PhonemeMode = 3 // separate phonemes with underscore characters )
type PositionType ¶
type PositionType C.espeak_POSITION_TYPE
type Voice ¶
type Voice struct { Name string // a given name for this voice Languages []struct { Priority uint8 // lower is more preferred Language string // language code with optional dialect } Identifier string // the filename for this voice Gender Gender Age uint8 // 0 = not specified, or the age in years }
func CurrentVoice ¶
func CurrentVoice() *Voice
Returns the *espeak.Voice data for the currently selected voice. This is not affected by temporary voice changes caused by SSML elements such as <voice> and <s>.
func ListVoices ¶
func ListVoices() []*Voice
Reads the voice files from espeak-data/voices and creates a slice of *espeak.Voice. All voices are listed in an undefined order.