Spaces:
Sleeping
Sleeping
Delete PhraseTTS.py
Browse files- PhraseTTS.py +0 -210
PhraseTTS.py
DELETED
|
@@ -1,210 +0,0 @@
|
|
| 1 |
-
import MS_TTS_Batch
|
| 2 |
-
import MS_TTS
|
| 3 |
-
import SkywindDict,EnglishDictAI,DictUtils
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def azureTTS(ssml_string,unitAudioPath):
|
| 7 |
-
# ssml_string.encode
|
| 8 |
-
if ssml_string.count('</voice>')<=50:
|
| 9 |
-
MS_TTS.tts(ssml_string,unitAudioPath)
|
| 10 |
-
else:
|
| 11 |
-
MS_TTS_Batch.tts(ssml_string,unitAudioPath)
|
| 12 |
-
|
| 13 |
-
ZH_VOICE = 'zh-CN-XiaochenMultilingualNeural'
|
| 14 |
-
# EN_VOICE = 'en-US-AvaMultilingualNeural'#太喜悦了,不行
|
| 15 |
-
EN_VOICE = "en-US-JaneNeural"
|
| 16 |
-
|
| 17 |
-
def generalTTS(text,outputAudioPath='',voice=''):
|
| 18 |
-
|
| 19 |
-
wordsSpeech=f'''
|
| 20 |
-
<voice name="{voice}">
|
| 21 |
-
{text}
|
| 22 |
-
</voice>
|
| 23 |
-
|
| 24 |
-
'''
|
| 25 |
-
|
| 26 |
-
# wordAudioPath=outputFilePath+'.wav'
|
| 27 |
-
|
| 28 |
-
ssml_string=f'''
|
| 29 |
-
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
|
| 30 |
-
{wordsSpeech}
|
| 31 |
-
</speak>
|
| 32 |
-
'''
|
| 33 |
-
|
| 34 |
-
# ssml_string.encode
|
| 35 |
-
|
| 36 |
-
azureTTS(ssml_string,outputAudioPath)
|
| 37 |
-
|
| 38 |
-
def wordsPronunciation(phraseList,outputAudioPath):
|
| 39 |
-
|
| 40 |
-
wordsSpeech=f'''
|
| 41 |
-
|
| 42 |
-
<voice name="{EN_VOICE}">
|
| 43 |
-
{'<break time="1s"/>'.join(phraseList)}
|
| 44 |
-
</voice>
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
'''
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# wordAudioPath=outputFilePath+'.wav'
|
| 51 |
-
|
| 52 |
-
ssml_string=f'''
|
| 53 |
-
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
|
| 54 |
-
{wordsSpeech}
|
| 55 |
-
</speak>
|
| 56 |
-
'''
|
| 57 |
-
|
| 58 |
-
# ssml_string.encode
|
| 59 |
-
|
| 60 |
-
azureTTS(ssml_string,outputAudioPath)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
def chineseDefinitionTTS(phraseList,outputAudioPath):
|
| 64 |
-
phraseMeaningSSML=''
|
| 65 |
-
dictResultList=[]
|
| 66 |
-
for phrase in phraseList:
|
| 67 |
-
dictResult = SkywindDict.query(phrase)
|
| 68 |
-
if not dictResult.get('definition'):
|
| 69 |
-
dictResult = EnglishDictAI.query(phrase)
|
| 70 |
-
|
| 71 |
-
print(dictResult)
|
| 72 |
-
dictResultList.append(dictResult)
|
| 73 |
-
|
| 74 |
-
chineseDefinition=dictResult.get('definition')
|
| 75 |
-
|
| 76 |
-
spokenChineseDefinition = DictUtils.toSpokendefinition(chineseDefinition)
|
| 77 |
-
|
| 78 |
-
phraseMeaningSSML+=f'''
|
| 79 |
-
|
| 80 |
-
<voice name="{EN_VOICE}">
|
| 81 |
-
{phrase}
|
| 82 |
-
<p><say-as interpret-as="characters">{phrase if ' ' not in phrase else ''}</say-as></p>
|
| 83 |
-
{phrase}
|
| 84 |
-
</voice>
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
<voice name="{ZH_VOICE}">
|
| 88 |
-
<lang xml:lang="zh-CN">
|
| 89 |
-
<s>{spokenChineseDefinition}</s>
|
| 90 |
-
</lang>
|
| 91 |
-
</voice>
|
| 92 |
-
'''
|
| 93 |
-
|
| 94 |
-
# wordAudioPath=outputFilePath+'.wav'
|
| 95 |
-
|
| 96 |
-
ssml_string=f'''
|
| 97 |
-
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
|
| 98 |
-
{phraseMeaningSSML}
|
| 99 |
-
</speak>
|
| 100 |
-
'''
|
| 101 |
-
|
| 102 |
-
azureTTS(ssml_string,outputAudioPath)
|
| 103 |
-
return dictResultList
|
| 104 |
-
|
| 105 |
-
if __name__ == "__main__":
|
| 106 |
-
# chineseDefinitionTTS(['colleague', 'viable', 'crack', 'dissolve', 'reinforce', 'plumber', 'tilt', 'exploration'],'outputAudioPath.mp3')
|
| 107 |
-
# wordsPronunciation(['colleague', 'viable', 'crack', 'dissolve', 'reinforce', 'plumber', 'tilt', 'exploration'],'outputAudioPath.mp3')
|
| 108 |
-
words='''ditch
|
| 109 |
-
preparatory
|
| 110 |
-
immense
|
| 111 |
-
snare drum
|
| 112 |
-
stall
|
| 113 |
-
inhibit
|
| 114 |
-
anchor
|
| 115 |
-
priest
|
| 116 |
-
affordance
|
| 117 |
-
bump
|
| 118 |
-
integrity
|
| 119 |
-
eavesdrop
|
| 120 |
-
monetary
|
| 121 |
-
prerequisite
|
| 122 |
-
aggregate
|
| 123 |
-
benign
|
| 124 |
-
keynote
|
| 125 |
-
cognitive
|
| 126 |
-
apathy
|
| 127 |
-
nobility
|
| 128 |
-
underperform
|
| 129 |
-
insane
|
| 130 |
-
liable
|
| 131 |
-
conspiracy
|
| 132 |
-
proprietary
|
| 133 |
-
ditch
|
| 134 |
-
nuance
|
| 135 |
-
bicker
|
| 136 |
-
addictive
|
| 137 |
-
logarithm
|
| 138 |
-
intimately
|
| 139 |
-
peculiarly
|
| 140 |
-
eligible
|
| 141 |
-
apt
|
| 142 |
-
attribute
|
| 143 |
-
bizarre
|
| 144 |
-
misfortune
|
| 145 |
-
onlooker
|
| 146 |
-
precursor
|
| 147 |
-
curriculum
|
| 148 |
-
phobia
|
| 149 |
-
impedance
|
| 150 |
-
hands-off
|
| 151 |
-
introspection
|
| 152 |
-
decay
|
| 153 |
-
exploration
|
| 154 |
-
deposit
|
| 155 |
-
quarterly
|
| 156 |
-
workbench
|
| 157 |
-
phenomenon
|
| 158 |
-
indefinitely
|
| 159 |
-
bracket
|
| 160 |
-
invariably
|
| 161 |
-
clumsiness
|
| 162 |
-
dutiful
|
| 163 |
-
err
|
| 164 |
-
entrench
|
| 165 |
-
intrinsic
|
| 166 |
-
pin
|
| 167 |
-
calamity
|
| 168 |
-
collaborate
|
| 169 |
-
utterance
|
| 170 |
-
rudimentary
|
| 171 |
-
grievous
|
| 172 |
-
rectify
|
| 173 |
-
flexibility
|
| 174 |
-
smoothly
|
| 175 |
-
aerospace
|
| 176 |
-
saturated
|
| 177 |
-
realism
|
| 178 |
-
bummer
|
| 179 |
-
prominent
|
| 180 |
-
impact
|
| 181 |
-
spatial
|
| 182 |
-
semantic
|
| 183 |
-
appliance
|
| 184 |
-
deficient
|
| 185 |
-
insurance
|
| 186 |
-
prohibitive
|
| 187 |
-
anonymous
|
| 188 |
-
tuition
|
| 189 |
-
doctoral
|
| 190 |
-
master
|
| 191 |
-
bachelor
|
| 192 |
-
fringe
|
| 193 |
-
affiliate
|
| 194 |
-
pointless
|
| 195 |
-
emphasize
|
| 196 |
-
contractor
|
| 197 |
-
plumber
|
| 198 |
-
contiguity
|
| 199 |
-
curriculum vitae
|
| 200 |
-
dialect
|
| 201 |
-
domestic
|
| 202 |
-
nerd
|
| 203 |
-
faithfully
|
| 204 |
-
quarter
|
| 205 |
-
|
| 206 |
-
'''
|
| 207 |
-
wordsPronunciation(words.split(),'outputAudioPath.mp3')
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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