我用num2words作为pico2的输入,得到了很差的TTS

2024-05-17 16:03:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python脚本中,num2words似乎生成unicode文本。当它用作pico2wave的输入时,文本前面会加一个“u”。如何num2words生成ascii以便pico2wave正常工作

打印输出例如:

var1 = 12  

numb = numb2words(var1)  

print(numb)  

输出:u'twelve'

当用作pico的输入时,会说“uhsetween”


Tags: 文本脚本asciiunicodeprintpico打印输出var1
1条回答
网友
1楼 · 发布于 2024-05-17 16:03:50

可以使用unicodedata库将unicode转换为ascii

我们将使用unicodedata.normalize的“NFKD”形式进行转换。根据unicodata documentation

there are two additional normal forms based on compatibility equivalence. In Unicode, certain characters are supported which normally would be unified with other characters. For example, U+2160 (ROMAN NUMERAL ONE) is really the same thing as U+0049 (LATIN CAPITAL LETTER I). However, it is supported in Unicode for compatibility with existing character sets (e.g. gb2312).

The normal form KD (NFKD) will apply the compatibility decomposition, i.e. replace all compatibility characters with their equivalents.

因此,解决方案是:

import unicodedata

var1 = 12

numb = numb2words(var1)
numb = unicodedata.normalize('NFKD', numb).encode('ascii','ignore')

print(numb)

相关问题 更多 >