Rewriting process start codes to use call process<table><label> .... procedures
[sgc2.git] / ToneProt / synthesizeMandarin.praat
blobe382ac2e06b39c079133092faf105ec7826d3423
1 #! praat
3 # Synthesize Mandarin by concatenating syllables.
4 # Has some very rudimentary kludges for creating
5 # neutral tone syllables from fourth tone syllables 
6 # (should not sound acceptable)
8 # The sourcedir should be the mandaring sounds dir.
10 form type pinyin
11     word pinyin ni3hao3
12     word sourcedir ../wordlists/MandarinSounds
13 endform
15 pinyinProcessed$ = replace_regex$(pinyin$, "^\s*([a-zA-Z]+)3([a-zA-Z]+)3$", "\12\23", 0)
17 numSounds = 0
18 while pinyinProcessed$ > " "
19         currentsyllable$ =  replace_regex$(pinyinProcessed$, "^\s*([a-zA-Z]+[0-9]).*$", "\1", 0)
20         pinyinProcessed$ = replace_regex$(pinyinProcessed$, "^\s*[a-zA-Z]+[0-9](.*)$", "\1", 0)
22         if rindex_regex(currentsyllable$, "0\s*$") > 0
23                 newSyllable$ = replace_regex$(currentsyllable$, "^\s*([a-zA-Z]+)0$", "\14", 0)
24                 Read from file... 'sourcedir$'/'newSyllable$'.wav
25                 Rename... 'currentsyllable$'
26                 Lengthen (PSOLA)... 75 600 0.7
27                 Rename... Shortened
28                 select Sound 'currentsyllable$'
29                 Remove
30                 select Sound Shortened
31                 Multiply... 0.71
32                 To Manipulation... 0.01 75 600
33                 Extract pitch tier
34                 Rename... Shortened
35                 Shift frequencies... 0 1000 -6 semitones
36                 select Manipulation Shortened
37                 plus PitchTier Shortened
38                 Replace pitch tier
39                 select Manipulation Shortened
40                 Get resynthesis (PSOLA)
41                 Rename... 'currentsyllable$'
43                 # Clean up
44                 select Manipulation Shortened
45                 plus Sound Shortened
46                 plus PitchTier Shortened
47                 Remove
49                 select Sound 'currentsyllable$'
50         else
51                 Read from file... 'sourcedir$'/'currentsyllable$'.wav
52         endif
53         Rename... Sound
54         To TextGrid (silences)... 100 0 -20 0.1 0.1 silent sounding
55         Rename... Grid
56         numIntervals = Get number of intervals... 1
57         startTime = -1
58         endTime = -1
59         for i from 1 to numIntervals
60                 select TextGrid Grid
61                 currentLabel$ = Get label of interval... 1 'i'
62                 if currentLabel$ = "sounding"
63                         if startTime <= -1
64                                 startTime = Get starting point... 1 'i'
65                         endif
66                         endTime = Get end point... 1 'i'
67                 endif
68         endfor
69         if startTime > 0.050 and rindex_regex(currentsyllable$, "^[ktpgdbz]") > 0
70             startTime = startTime - 0.050
71         endif
72         select Sound Sound
73         Extract part... 'startTime' 'endTime' Rectangular 1.0 0
74         Rename... 'currentsyllable$'
76         select Sound Sound
77         plus TextGrid Grid
78         Remove
80         numSounds = numSounds + 1
81         if numSounds <= 1
82                 select Sound 'currentsyllable$'
83                 Rename... 'pinyin$'
84         else
85                 select Sound 'pinyin$'
86                 plus Sound 'currentsyllable$'
87                 Concatenate
88                 Rename... tmpSound
89                 select Sound 'pinyin$'
90                 plus Sound 'currentsyllable$'
91                 Remove
92                 select Sound tmpSound
93                 Rename... 'pinyin$'
94         endif
95 endwhile