espeak

package module
v1.0.0-...-48cb06b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: MIT Imports: 4 Imported by: 0

README

Import path: gopkg.in/BenLubar/espeak.v1

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.


Although gopkg.in/BenLubar/espeak.v1 is licensed under the MIT license, libespeak is licensed under the GPL. This means that the compiled version of this package can only be used by GPL-compatible programs. Sorry, but there's nothing I can do about it.

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

View Source
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)
)
View Source
const (
	InitializePhonemeEvents = 1 << 0
	InitializePhonemeIPA    = 1 << 1
	InitializeDontExit      = 1 << 15
)
View Source
const (
	PosCharacter = PositionType(C.POS_CHARACTER)
	PosWord      = PositionType(C.POS_WORD)
	PosSentence  = PositionType(C.POS_SENTENCE)
)
View Source
const (
	SynthSSML     = uint(C.espeakSSML)
	SynthPhonemes = uint(C.espeakPHONEMES)
	SynthEndPause = uint(C.espeakENDPAUSE)
)

Variables

View Source
var (
	ErrInternalError = errors.New("espeak: internal error")
	ErrBufferFull    = errors.New("espeak: buffer full")
	ErrNotFound      = errors.New("espeak: not found")
)

Functions

func Cancel

func Cancel() error

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 Pitch

func Pitch() int

Pitch base, [0, 100]. 50 = normal.

func Range

func Range() int

Range of pitch, [0, 100]. 0 = monotone, 50 = normal.

func Rate

func Rate() int

Rate of speech in words per minute, [80, 450].

func SetPitch

func SetPitch(percent int) error

func SetRange

func SetRange(percent int) error

func SetRate

func SetRate(wpm int) error

func SetSynthCallback

func SetSynthCallback(f func(wav []int16, events []Event) (stop bool))

func SetURICallback

func SetURICallback(f func(uri, base string) (replaceWithText bool))

func SetVoiceByName

func SetVoiceByName(name string) error

Searches for a voice with a matching "name" field. Language is not considered.

func SetVoiceByProperties

func SetVoiceByProperties(name, language string, gender Gender, age uint8, variant int) error

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 SetVolume

func SetVolume(percent int) error

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.

func Volume

func Volume() int

Volume, [0, ∞). 0 = silent, 100 = normal full volume, >100 may be distorted.

Types

type AudioOutput

type AudioOutput C.espeak_AUDIO_OUTPUT

type BaseEvent

type BaseEvent struct {
	UniqueIdentifier uint
	TextPosition     int
	Length           int
	AudioPosition    int
	Sample           int
	UserData         interface{}
}

type EndEvent

type EndEvent struct {
	BaseEvent
}

End of sentence or clause

type Event

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

type Gender

type Gender uint8
const (
	NoGender Gender = iota
	Male
	Female
)

type ListTerminatedEvent

type ListTerminatedEvent struct {
	BaseEvent
}

Retrieval mode: terminates the event list.

type MarkEvent

type MarkEvent struct {
	BaseEvent
	Name string
}

<mark> element

type MsgTerminatedEvent

type MsgTerminatedEvent struct {
	BaseEvent
}

End of message

type PhonemeEvent

type PhonemeEvent struct {
	BaseEvent
	String string
}

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 PlayEvent

type PlayEvent struct {
	BaseEvent
	Name string
}

<audio> element

type PositionType

type PositionType C.espeak_POSITION_TYPE

type SampleRateEvent

type SampleRateEvent struct {
	BaseEvent
}

Set sample rate

type SentenceEvent

type SentenceEvent struct {
	BaseEvent
	Number int
}

Start of sentence

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.

func ListVoicesByProperties

func ListVoicesByProperties(name, language string, gender Gender, age uint8) []*Voice

Reads the voice files from espeak-data/voices and creates a slice of *espeak.Voice. Matching voices are listed in preference order.

type WordEvent

type WordEvent struct {
	BaseEvent
	Number int
}

Start of word

Directories

Path Synopsis
wav

Jump to

Keyboard shortcuts

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