espeak
Bindings to espeak-ng's C library
Introduction
Text to speech? Text to phonemes? Phonemes to speech? This library should have you covered. The goal was to expose espeak-ng's C library through Chicken while also doing a little more of the work internally to make the API more user-friendly. Currently, the parts of the library related to callbacks and events are not supported.
Procedures
Synthesis
[procedure] (say text #!key sync name language identifier gender age variant rate volume pitch range punctuation capitals wordgap)A high-level speech synthesis addition to the library. sync is a boolean that determines if the function should wait for the audio to be spoken before returning. The parameters name - variant get passed directly into make-voice, while the rest are set using set-parameter!. Subsequent calls use the last settings (unless explicitly changed in the say call, or set by set-voice-by* functions or set-parameter!):
(say "This is an example." gender: gender/female rate: 200) (say "This will sound the same.")[procedure] (synth text #!key (position 0) (position-type pos/char) (end-position #f) (ssml #f) (phonemes #f) (endpause #f))
[procedure] (synth-mark text index-mark #!key (end-position 0) (ssml #f) (phonemes #f) (endpause #f))
The basic speech synthesis function.
- position
- The position in the text where speaking starts.
- position_type
- One of pos/char, pos/word, or pos/sentence. It seems pos/char currently acts like pos/word, and the other two are 1-indexed.
- end_position
- A character position at which speaking will stop.
- ssml
- elements within < > are treated as espeak SSML.
- phonemes
- elements within [[ ]] are treated as Kirshenbaum encoded phonemes
- endpause
- wheter to add a sentence pause to the end of the text.
synth-mark is like synth, but an SSML <mark name="example"> element indicates the beginning of speech, with the name passed to index-mark
[procedure] (key k)[procedure] (char c)
Speak the name of the keyboard key (a single-character length string) or character, respectively. key will speak a full string if it's longer than one character.
[procedure] (cancel)Immediately stop 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.
[procedure] (playing?)Determines whether audio is playing or not.
[procedure] (synchronize)Returns when all audio data has been spoken.
Phonemes
[procedure] (text->phonemes input #!key ipa tie separator)Translates an input string into a string of phonemes. By default, uses Kirshenbaum (ascii) encoding, but will output UTF8 if ipa is #t. You can specify a character to separate the phonemes with using separator. If tie is set, that character is used as a tie within multi-letter phoneme names.
Examples:
(text->phonemes "hello") ;; => "h@l'oU" (text->phonemes "hello" ipa: #t) ;; => "həlˈəʊ" (text->phonemes "hello" ipa: #t separator: #\-) ;; => "h-ə-l-ˈəʊ" (text->phonemes "hello my name is" ipa: #t tie: #t separator: #\x35c) ;; => "həlˈə͜ʊ ma͜ɪ nˈe͜ɪm ɪz"
Settings
[procedure] (make-voice #!key name language identifier (gender 0) (age 0) (variant 0))[procedure] voice?
[procedure] voice-name
[procedure] voice-name-set!
[procedure] voice-language
[procedure] voice-language-set!
[procedure] voice-identifier
[procedure] voice-identifier-set!
[procedure] voice-gender
[procedure] voice-gender-set!
[procedure] voice-age
[procedure] voice-age-set!
[procedure] voice-variant
[procedure] voice-variant-set!
make-voice returns a voice record that is mostly useful for filtering the results of list-voices or passing to set-voice-by-properties!. Name, language, and identifier should all be either #f or strings.
[constant] gender/none[constant] gender/male
[constant] gender/female
Allowed values for gender parameter of make-voice.
[procedure] (set-parameter! parameter value #!optional relative)Set the value of a parameter, which can be any of:
- param/rate
- speaking speed in words per minute, 80 - 450. Defaults to 175.
- param/volume
- volume, 0 or more. Defaults to 100. Values greater than that may produce amplitude compression or distortion.
- param/pitch
- base pitch, 0-100. Defaults to 50.
- param/range
- pitch range, 0-100. Defaults to 50.
- param/punctuation
- which punctuation characters to announce: punct/none, punct/some, or punct/all.
- param/captials
- announce capital letters by: capitals/none, capitals/sound-icon, capitals/spelling, 3+ by raising pitch, where the value corresponds to the amount in Hz by which the pitch is raised.
- param/wordgap
- pause between words in units of 10mS at the default speed.
Get the current or default value of a parameter.
[procedure] (set-punctuation-list! str)Specifies a string list of punctuation characters whose names are to be spoken when the value of the punctuation parameter is set to pnuct/some.
[procedure] (list-voices #!optional voice)Can be used to list all voices, or filter voices by properties. For example, to list all spanish voices:
(list-voices (make-voice language: "es"))
[procedure] (set-voice-by-properties! voice)
[procedure] (set-voice-by-name! name)
[procedure] (set-voice-by-file! filepath)
Can be used to select a voice to be used for synthesis functions by properties. For example:
;; Set to spanish by name (set-voice-by-properties! (make-voice name: "Spanish (Spain)")) ;; Set to a spanish voice (set-voice-by-properties! (make-voice language: "es")) ;; Set to an english voice (set-voice-by-properties! (make-voice language: "en")) ;; Specify dialect (set-voice-by-properties! (make-voice language: "en-uk")) ;; Set to gender (set-voice-by-properties! (make-voice language: gender/female)) ;; Combine, female spanish (set-voice-by-properties! (make-voice gender: gender/female language: "es"))[procedure] (get-current-voice)
Returns the currently set voice.
[procedure] (reset-defaults!)Added in Chicken - resets all parameters and voice to defaults.
Other
[procedure] (initialize #!key (output output/playback) (buflength 0) (path #f) (phoneme-events #f) (phoneme-ipa #f) (dont-exit #f))A binding for espeak_Initialize. Unless you want change path, you shouldn't have to call this, as it's implicitly called by the first function that may need it. The rest of the parameters are currently probably useless without support for events and callbacks.
[constant] output/playback[constant] output/retrieval
[constant] output/synchronous
[constant] output/synch-playback
Allowed values for output parameter of initialize
[procedure] (terminate)Last function to be called. Shouldn't be necessary (don't quote me on this).
[procedure] (info)Returns version number string and path to espeak_data.
Author
Diego A. Mundo
Repository
https://git.sr.ht/~dieggsy/chicken-espeak
License
GPL-3.0
Version History
- 0.1.6
- Minor code quality improvement
- 0.1.1 - 0.1.5
- Various minor bug fixes
- 0.1.0
- Initial version.