如何获得英语单词的发音?增加 IPA-SAMPA
简 介: 为了获得英文单词的读音并进行显示,使用 eng_to_ipa 或者单词的 IPA, 然后通过自行编写的转换程序,将IPA 转换成 sampa并进行显示。
关键词
: sampa,ipa
Contents
§01 单词发音
英语的单词的认知需要同时配合他的发音才能够有更好的效果。在测试一些利用PYTHON完成中英文翻译的效果利用有道在线翻译对于TEASOFT
软件Python
附加程序进行了英语查询扩充,但是现在还缺少读音的提示,下面查看一些辅助的工具,看是否能够将这个功能补齐。
1.1 文字转语音
在 Python(九)- 音频文字转换 给出了几个语音模块:
- pyttsx3 :软件包,是系统内置的语音引擎实现发音,不生成
MP3
; - win32com:
Windows
操作系统内置的语音引擎实现文字发音;
在 更新pip3与pyttsx3文字语音转换 中指出在安装 pyttsx3
之前需要安装 pypiwin32
。
1.1.1 安装软件包
(1)安装 pypiwin32
python -m pip install pypiwin32
(2)安装 pyttsx3
python -m pip install pyttsx3
1.1.2 测试软件包
Ⅰ.汉语读音
import pyttsx3
engine = pyttsx3.init()
engine.say('人类真帅')
engine.runAndWait()
可以听到“人类真帅” 的输出语言。
Ⅱ.英语读音
engine.say(‘Windows is an OS.’)
也可以听到英文的读出(“Windows is an OS.”)
但是上述的输出有着明显的“机器人” 的强调,不是非常自认的语言。
1.2 wordnet
根据 volcabulary 软件模块,介绍volcabulary获得单词的信息。但是在安装volcabulary的时候出现错误。
python -m pip install nltk
1.2.1 测试 wordnet
import sys,os,math,time
import matplotlib.pyplot as plt
from numpy import *from nltk.corpus import wordnet
syns = wordnet.synsets('car')
print(syns)
测试结果:测试错误。 无法工作。
1.3 eng-to-ipa
在 Convert English text into the Phonetics using Python 介绍利用“eng-to-ipa” 获取英语单词的读音。
这个软件报是将英语单词转换为 IPA (International Phonetic Alphabet)。
详细的介绍可以参见: English to IPA (eng_to_ipa) 。
1.3.1 安装软件包
python -m pip install eng-to-ipa
▲ 图1.3.1 python -m pip install eng-to-ipa
1.3.2 测试软件包
import sys,os,math,time
import matplotlib.pyplot as plt
from numpy import *import eng_to_ipa as pipa = p.convert("Hello Geeks.")filename = r'd:\temp\1.txt'
with open(filename, 'w', encoding='utf-8') as f:f.write(ipa)print('\a')
▲ 图1.3.2 音标对应的显示
ipa = p.convert("Using ipa-list() instead of convert()")
▲ 图1.3.3 音标显示
ipa = p.ipa_list("Yes I am geeks, How are you.")
▲ 图1.3.4 音标显示
1.3.3 get_rhymes
py = p.get_rhymes('test')
printf(py)
['abreast', 'acquiesced', 'addressed', 'addwest', 'arrest', 'assessed', 'attest', 'behest', 'bequest', 'best', 'beste', 'blessed', 'blest', 'breast', 'brest', 'bud-test', "c'est", 'caressed', 'celeste', 'charest', 'chest', 'chrest', 'coalesced', 'compressed', 'confessed', 'congest', 'contest', 'crest', "d'allest", 'depressed', 'dest', 'detest', 'digest', 'digressed', 'dispossessed', 'distressed', 'divest', 'dressed', 'eastern-west', 'est', 'expressed', 'farwest', 'fessed', 'fest', 'finessed', 'gest', 'guessed', 'guest', 'impressed', 'indigest', 'infest', 'ingest', 'intrawest', 'invest', 'jest', 'key_west', 'lest', 'messed', 'mest', 'midwest', 'molest', 'natwest', 'nest', 'neste', 'northwest', 'norwest', 'obsessed', 'oppressed', 'penwest', 'pest', 'possessed', 'pressed', 'prest', 'professed', 'progressed', 'protest', 'quest', 'rearrest', 'reassessed', 'recessed', 'reinvest', 'repossessed', 'repressed', 'request', 'rest', 'retest', 'self-professed', 'southwest', 'stateswest', 'stressed', 'suggest', 'suppressed', 'sylvest', 'telequest', 'telewest', 'transgressed', 'trest', 'unaddressed', 'undressed', 'unimpressed', 'unrest', 'vest', 'west', 'wrest', 'yest', 'yoest', 'zest']
1.3.4 如何显示IPA?
很尴尬的问题,就是eng_to_ipa输出的文字中包含有很多无法直接显示的字符。那么如何将其进行转化成ASCII?
在 ipapy 0.0.9.0 给出了关于IPA 的python软件包。
(1)安装 IPAPY
python -m pip install ipapy
测试了这个软件,但是好像无法进行转换。
§02 显示IPA
在现在的TEASOFT软件中还无法显示 IPA 的代码。该如何将IPA转换成标准的ASCII呢?
在 IPA to plain simple English translator 给出了这方面的提问。 也就是将IPA转换成 : American Heritage Dictionary uses 。
2.1 转换程序
ipa_converter 给出了一个将IPA转换成 SAMPA - computer readable phonetic alphabet
2.1.1 转换程序
import eng_to_ipa as p
import string#------------------------------------------------------------
sampafile = r'D:\Temp\sampa.cfg'
table = {}
with open(sampafile, 'r', encoding='utf8') as f:for line in f:line = line.strip()if line == '': continuerow = line.split()sampa_symb = row[0]ipa_symb = row[1]table[ipa_symb] = sampa_symb#------------------------------------------------------------
ipa = p.convert("Yes I am geeks, How are you.")out = []
for c in ipa:if c in table: c= table[c]elif c not in string.printable: c = ''out.append(c)printf(''.join(out))
2.1.2 测试结果
ipa = p.convert("Yes I am geeks, How are you.")
jEs aI {m giks, haU @r ju.
ipa = p.convert("instead")
%In"stEd
2.2 gruut-ipa
从 Gruut IPA 安装软件包。
▲ 图2.1.1 SAMPA 对应表格
2.2.1 安装软件包
python -m pip install gruut-ipa
IPA | eSpeak | Sampa | Description |
---|---|---|---|
i | i | i | close front unrounded vowel |
y | y | y | close front rounded vowel |
ɨ | i | 1 | close central unrounded vowel |
ʉ | u | } | close central rounded vowel |
ɯ | u- | M | close back unrounded vowel |
u | u | u | close back rounded vowel |
ɪ | I | I | near-close near-front unrounded vowel |
ʏ | I. | Y | near-close near-front rounded vowel |
ʊ | U | U | near-close near-back rounded vowel |
e | e | e | close-mid front unrounded vowel |
ø | Y | 2 | close-mid front rounded vowel |
ɘ | @ | @ | close-mid central unrounded vowel |
ɵ | @. | 8 | close-mid central rounded vowel |
ɤ | o- | 7 | close-mid back unrounded vowel |
o | o | o | close-mid back rounded vowel |
ɛ | E | E | open-mid front unrounded vowel |
œ | W | 9 | open-mid front rounded vowel |
ɜ | V | 3 | open-mid central unrounded vowel |
ɞ | O | 3 | open-mid central rounded vowel |
ʌ | V | V | open-mid back unrounded vowel |
ɔ | O | O | open-mid back rounded vowel |
æ | a | { | near-open front unrounded vowel |
ɐ | V | 6 | near-open central unrounded vowel |
a | a | a | open front unrounded vowel |
ɶ | W | & | open front rounded vowel |
ɑ | A | A | open back unrounded vowel |
ɒ | A. | Q | open back rounded vowel |
m | m | m | voiced bilabial nasal |
ɱ | M | F | voiced labio-dental nasal |
n | n | n | voiced alveolar nasal |
ɳ | n. | n` | voiced retroflex nasal |
ŋ | N | N | voiced velar nasal |
ɴ | n | N | voiced uvular nasal |
p | p | p | voiceless bilabial plosive |
b | b | b | voiced bilabial plosive |
t | t | t | voiceless alveolar plosive |
d | d | d | voiced alveolar plosive |
ʈ | t. | t` | voiceless retroflex plosive |
ɖ | d. | d` | voiced retroflex plosive |
c | c | c | voiceless palatal plosive |
ɟ | J | J | voiced palatal plosive |
k | k | k | voiceless velar plosive |
ɡ | g | g | voiced velar plosive |
g | g | g | voiced velar plosive |
q | q | q | voiceless uvular plosive |
ɢ | G | G | voiced uvular plosive |
ʡ | > | voiceless pharyngeal plosive | |
ʔ | ? | ? | voiceless glottal plosive |
p͡f | pf | pf | voiceless labio-dental affricate |
b͡v | bv | bv | voiced dental affricate |
t̪͡s | ts | t ds | voiceless dental affricate |
t͡s | ts | ts | voiceless alveolar affricate |
d͡z | dz | dz | voiced alveolar affricate |
t͡ʃ | tS | tS | voiceless post-alveolar affricate |
d͡ʒ | dZ | dZ | voiced post-alveolar affricate |
ʈ͡ʂ | tS | ts` | voiceless retroflex affricate |
ɖ͡ʐ | dz | dz` | voiced retroflex affricate |
t͡ɕ | tS; | ts | voiceless palatal affricate |
d͡ʑ | dZ; | dz | voiced palatal affricate |
k͡x | k | k x | voiceless velar affricate |
ɸ | F | p | voiceless bilabial fricative |
β | B | B | voiced bilabial fricative |
f | f | f | voiceless labio-dental fricative |
v | v | v | voiced labio-dental fricative |
θ | T | T | voiceless dental fricative |
ð | D | D | voiced dental fricative |
s | s | s | voiceless alveolar fricative |
z | z | z | voiced alveolar fricative |
ʃ | S | S | voiceless post-alveolar fricative |
ʒ | Z | Z | voiced post-alveolar fricative |
ʂ | s. | s` | voiceless retroflex fricative |
ʐ | z. | z` | voiced palatal fricative |
ç | C | C | voiceless palatal fricative |
x | x | x | voiceless velar fricative |
ɣ | Q | G | voiced velar fricative |
χ | X | X | voiceless uvular fricative |
ʁ | g | R | voiced uvular fricative |
ħ | H | X | voiceless pharyngeal fricative |
h | h | h | voiceless glottal fricative |
ɦ | h<?> | h | voiced glottal fricative |
w | w | w | voiced bilabial approximant |
ʋ | v# | v | voiced labio-dental approximant |
ɹ | r | r | voiced alveolar approximant |
ɻ | r. | r ` | voiced retroflex approximant |
j | j | j | voiced palatal approximant |
ɰ | Q | M | voiced velar approximant |
ⱱ | ⱱ | ⱱ | voiced labio-dental flap |
ɾ | * | 4 | voiced alveolar flap |
ɽ | *. | r` | voiced retroflex flap |
ʙ | b | B | voiced bilabial trill |
r | r | r | voiced alveolar trill |
ʀ | r | R | voiced uvular trill |
l | l | l | voiced alveolar lateral-approximant |
ɫ | l | 5 | voiced alveolar lateral-approximant |
ɭ | l. | l` | voiced retroflex lateral-approximant |
ʎ | l^ | L | voiced palatal lateral-approximant |
ʟ | L | L | voiced velar lateral-approximant |
ə | @ | @ | schwa |
ɚ | 3 | @` | r-coloured schwa |
ɝ | 3 | @` | r-coloured schwa |
ɹ̩ | r- | r ̩ | voiced alveolar approximant |
这个软件包似乎只能通过命令行来调用。
2.3 SAMPA字符对应表格
下面表格从 sampa.cfg 拷贝粘贴过来。
A ɑ script a open back unrounded, Cardinal 5, Eng. start
{ æ ae ligature near-open front unrounded, Eng. trap
6 ɐ turned a open schwa, Ger. besser
Q ɒ turned script a open back rounded, Eng. lot
E ɛ epsilon open-mid front unrounded, C3, Fr. même
@ ə turned e schwa, Eng. banana
3 ɜ rev. epsilon long mid central, Eng. nurse
I ɪ small cap I lax close front unrounded, Eng. kit
O ɔ turned c open-mid back rounded, Eng. thought
2 ø o-slash close-mid front rounded, Fr. deux
9 œ oe ligature open-mid front rounded, Fr. neuf
& ɶ s.c. OE lig. open front rounded
U ʊ upsilon lax close back rounded, Eng. foot
} ʉ barred u close central rounded, Swedish sju
V ʌ turned v open-mid back unrounded, Eng. strut
Y ʏ small cap Y lax [y], Ger. hübsch
B β beta voiced bilabial fricative, Sp. cabo
C ç c-cedilla voiceless palatal fricative, Ger. ich
D ð eth voiced dental fricative, Eng. then
G ɣ gamma voiced velar fricative, Sp. fuego
L ʎ turned y palatal lateral, It. famiglia
J ɲ left-tail n palatal nasal, Sp. año
N ŋ eng velar nasal, Eng. thing
R ʁ inv. s.c. R vd. uvular fric. or trill, Fr. roi
S ʃ esh voiceless palatoalveolar fricative, Eng. ship
T θ theta voiceless dental fricative, Eng. thin
H ɥ turned h labial-palatal semivowel, Fr. huit
Z ʒ ezh (yogh) vd. palatoalveolar fric., Eng. measure
? ʔ dotless ? glottal stop, Ger. Verein, also Danish stød
: ː length mark length mark
" ˈ vertical stroke primary stress *
% ˌ low vert. str. secondary stress
s' ʂ Added for Russian support (ш)
s\ ɕ Added for Russian support (щ)
s' ʐ Added for Russian support (ж)
z\ ʑ Added for Russian support (ж)
1 ɨ Added for Russian support (и, sometimes ы)
8 ɵ Added for Russian support (ё)
_j ʲ Added for Russian support (ь)
将上述文本存储粘贴在 notepad中,并以 ‘utf-8’ 格式进行存储。
#!/usr/bin/pythonfrom __future__ import print_function
from string import printable
import sys, localeif __name__ == '__main__':from argparse import ArgumentParserparser = ArgumentParser(description='Converts IPA input to ASCII output. Does not handle certain cases: nasals, tones, syllabic consonants, and non-SAMPA representable phonetic symbols. Writes to stdout.')parser.add_argument('-c','--config',help='Name of the configuration table. Defaults to "sampa.cfg" in the working directory.',default='sampa.cfg')parser.add_argument('source',help='IPA symbols to convert.')args = parser.parse_args(sys.argv[1:])config = args.configsource = args.source.decode(locale.getpreferredencoding())print(source)config = open(config,'r')table = {}for line in config:line=line.strip()if line == '': continuerow = line.split()sampa_symb = row[0].decode('utf-8')ipa_symb = row[1].decode('utf-8')table[ipa_symb] = sampa_symbout = []for c in source:if c in table: c = table[c]elif c not in printable: c = ''out.append(c)print(''.join(out))
§03 改造程序
3.1 改造原料
sampa.cfg : 对应反映表格,是一个 “utf-8” 格式的文本文件。
代码:
import stringsampafile = r'D:\Python\Cmd\sampa.cfg'
table = {}
with open(sampafile, 'r', encoding='utf8') as f:for line in f:line = line.strip()if line == '': continuerow = line.split()sampa_symb = row[0]ipa_symb = row[1]table[ipa_symb] = sampa_symbdef ipa2sampa(ipa):out = []for c in ipa:if c in table: c = table[c]elif c not in string.printable: c = ''out.append(c)return ''.join(out)
3.2 改造小程序
主要改造的小程序包括:
- cal
- cdtm
3.2.1 增加IPA-SAMPA
#------------------------------------------------------------
import eng_to_ipa as ipa
import stringsampafile = r'D:\Python\Cmd\sampa.cfg'
table = {}
with open(sampafile, 'r', encoding='utf8') as f:for line in f:line = line.strip()if line == '': continuerow = line.split()sampa_symb = row[0]ipa_symb = row[1]table[ipa_symb] = sampa_symbdef ipa2sampa(ipa):out = []for c in ipa:if c in table: c = table[c]elif c not in string.printable: c = ''out.append(c)return ''.join(out)#------------------------------------------------------------
import json
import requestsdef translate(word):url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null'key = {'type': "AUTO",'i': word,"doctype": "json","version": "2.1","keyfrom": "fanyi.web","ue": "UTF-8","action": "FY_BY_CLICKBUTTON","typoResult": "true"}response = requests.post(url, data=key)if response.status_code == 200:return response.textelse:return Nonedef get_reuslt(repsonse):result = json.loads(repsonse)origin = result['translateResult'][0][0]['src']target = result['translateResult'][0][0]['tgt']originflag = 1targetflag = 1for c in origin:if ord(c) >= 0x80:originflag = 0breakfor c in target:if ord(c) >= 0x80:targetflag = 0breakoriginsampa = ''targetsampa = ''if originflag > 0:originsampa = "/%s/"%ipa2sampa(ipa.convert(origin))for c in originsampa:if c not in string.printable:originsampa = ''breakif targetflag > 0:targetsampa = "/%s/"%ipa2sampa(ipa.convert(target))for c in targetsampa:if c not in string.printable:targetsampa = ''breakprintf ("%s%s --> %s%s" %(result['translateResult'][0][0]['src'], originsampa,result['translateResult'][0][0]['tgt'], targetsampa))
3.2.2 允许结果
靠谱 --> By spectrum/baI "spEktr@m/
command/k@"m{nd/ --> 命令
python --> python
input/"In%pUt/ --> 输入
python --> python
cmd/cmd*/ --> cmd/cmd*/append/@"pEnd/ --> 附加input/"In%pUt/ --> 输入
python --> python
command/k@"m{nd/ --> 命令命令 --> The command/D@ k@"m{nd/
事情 --> things/TINz/
input/"In%pUt/ --> 输入backup/"b{%k@p/ --> 备份
※ 总 结 ※
为了获得英文单词的读音并进行显示,使用 eng_to_ipa 或者单词的 IPA, 然后通过自行编写的转换程序,将IPA 转换成 sampa并进行显示。
■ 相关文献链接:
- 测试一些利用PYTHON完成中英文翻译的效果
- Python(九)- 音频文字转换
- 更新pip3与pyttsx3文字语音转换
- volcabulary
- Convert English text into the Phonetics using Python
- English to IPA (eng_to_ipa)
- ipapy 0.0.9.0
- IPA to plain simple English translator
- ipa_converter
- SAMPA - computer readable phonetic alphabet
- Gruut IPA
- sampa.cfg
● 相关图表链接:
- 图1.3.1 python -m pip install eng-to-ipa
- 图1.3.2 音标对应的显示
- 图1.3.3 音标显示
- 图1.3.4 音标显示
- 图2.1.1 SAMPA 对应表格
如何获得英语单词的发音?增加 IPA-SAMPA相关推荐
- 英语单词如何正确发音?入股血赚!!!
1. 发音基础介绍 音素:元音 辅音 单词:重音 失去爆破 浊化 三单 过去式过去分词 句子:语调 重音 弱读 连读 缩读 段落:意群 元音字母: A.E.I.O.U 2. 音节的定义 英语单词在发音 ...
- 计算机英语词汇谐音记忆,英语单词的谐音记忆法
英语单词的谐音记忆法 谐音法就是利用英语单词的发音的谐音进行记忆的方法.由于英语是拼音文字,看到一个单词可以很容易地猜到它的发音;听到一个单词的发音也可以很容易地想到它的拼写.所以,如果谐音法使用得当 ...
- java的英语单词发音_最长英文单词完整发音读完需要3.5个小时?
原标题:最长英文单词完整发音读完需要3.5个小时? 英文是多少童鞋的心病嘞?来童鞋们举个手先! 我们从上学开始便与英文不死不休,在10多年的学业生涯中,英文与多少童鞋结下了深仇大恨.然而有些单词却连土 ...
- 口语:英语单词发音规则
英语单词发音规则[@more@] 一.元音字母在重读音节中的读音 元音字母 读 音 例 词 a 在开音节中 [ei] name plane Jane baby cake 在闭音节中 [æ] bag d ...
- 英语单词SQL数据库一千词带音标例句发音【安卓SQLite网页MySQL皆可用】
[一千英语单词加翻译音标例句发音sql文件db文件] 蛋疼,上传完文件发现默认就是5C币一次,居然不是免费的,这里直接放出sql文件好了.供大家免费复制. 包含了一千多个英语单词的sql文件.移动安卓 ...
- javascript英语单词音节拆分_英语启蒙:自然拼读之单词合成与分割
这是软实力英语的第542篇原创文章. 培养孩子的语音意识,是培养阅读能力的重要组成部分.研究表明,语音意识差的孩子阅读能力也较差. 具体来说,就是自然拼读(phonics)的过程,包括:1. 字母及字 ...
- 背英语单词词根词缀的重要性
原文地址:https://www.zhihu.com/question/22896159 18 个回答 得得得君 有时候,了解词根会给你带来"哇,原来是这样"的惊叹. 我想,就算单 ...
- python写水仙花的作文_怎样背英语单词才高效?
不定期更新...... 叔现在开坑讲阅读,教你像读中文一样流畅地一遍读懂英文:如何提高英文阅读水平?www.zhihu.com 目录答疑区 正文 英语单词到底是什么 怎么选择单词书 如何培养背单词的 ...
- 英语单词词根词缀和词性转换
英语中常见的后缀 一.名词性后缀 1,-age为抽象名词后缀,表示行为,状态和全体总称 percentage百分数,百分率,voltage电压,伏特数,lavage灌洗,洗,出法,gavage管词法, ...
最新文章
- Leangoo背景更新-看板背景任你选!!!
- ES学习笔记之-AvgAggregation的实现过程分析
- 2013年全球最佳工作
- JAVA黑白圆圈图形_CSS3 黑白交替旋转圆圈
- 通过CMOS设置定时开机
- python中lines是什么类型_Python中splitlines()方法的使用简介
- String使用注意一
- 瑞士:冰川融化 阿尔卑斯部分山体面临坍塌
- pandas多列同时赋值_在pandas DataFram中减去多列并追加结果
- x64位windows上程序开发的注意事项
- 无法打开运行空间池,服务器管理器winrm插件可能已损坏或丢失
- mysql学习笔记(常用语句)
- 鼠标跟随事件jQuery
- SpringBoot数据库连接池常用配置(mysql+sqlServer)
- 【R语言数据科学】(十三):有趣的概率学(下)
- 【bzoj4826】[Hnoi2017]影魔
- 2022年最新浙江道路运输安全员真题题库及答案
- PyCharm添加Anaconda中的虚拟环境,Python解释器出现Conda executable is not found(解决方案)
- Bootstrap4动态切换主题
- Oracle练习题(九)