This code example shows how to load a voice in Python from a function that first does extra processing on the voice. It can also be found at speect/swig/python/examples/ibibio_frontend/ibibio_voice.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # note that the function name must be "load_voice"
def load_voice():
import speect
import speect.uttproc_cb # utterance callback interface
# load voice json file
voice = speect.SVoice("voice.hts.json") # load voice definition
# load and add g2p
import speect.modules.g2p_rewrites_festival as g2p_rewrites
import ibibio_g2p
ig2p = g2p_rewrites.G2P_Rewrites_Festival(ibibio_g2p.rules, ibibio_g2p.sets)
# set g2p in voice
voice.data_set("g2p", ig2p)
# load and add syllabification
import speect.modules.syllab_rewrites as syllab_rewrites
import ibibio_syll
isyll = syllab_rewrites.Syllab_Rewrites(ibibio_syll.rules, ibibio_syll.sets)
# set syllabification in voice
voice.data_set("syllabification", isyll)
#
# Create utterance processors
#
# create tokenizer
import speect.modules.tokenize_processor as tokenize_processor
tok_utt_proc = speect.SUttProcessor.callback(tokenize_processor.utt_processor)
# create normalizer
import speect.modules.normalize_processor as normalize_processor
norm_utt_proc = speect.SUttProcessor.callback(normalize_processor.utt_processor)
# create phrasing processor
import speect.modules.phrasing_processor as phrasing_processor
phrasing_utt_proc = speect.SUttProcessor.callback(phrasing_processor.utt_processor)
# create lexical lookup processor
import speect.modules.lexical_processor as lexical_processor
lexlookup_utt_proc = speect.SUttProcessor.callback(lexical_processor.utt_processor)
# create pause insertion processor
import speect.modules.pause_processor as pause_processor
pause_utt_proc = speect.SUttProcessor.callback(pause_processor.utt_processor)
#
# Replace voice definition file processors with above
#
voice.uttProcessor_set("Tokenize", tok_utt_proc)
voice.uttProcessor_set("Normalize", norm_utt_proc)
voice.uttProcessor_set("Phrasify", phrasing_utt_proc)
voice.uttProcessor_set("LexLookup", lexlookup_utt_proc)
voice.uttProcessor_set("Pauses", pause_utt_proc)
return voice
|