【发布时间】:2020-05-02 10:29:53
【问题描述】:
我正在制作一个脚本,它接受一个随机单词并获取该单词的定义,然后它将其转换为语音并播放它,但由于某种原因,每当我尝试获取该单词的定义时,它只会返回 false ,有没有办法解决这个问题?
注意:我使用词汇表来获取单词的定义,使用随机词来获取将要定义的随机词。
脚本:
from gtts import gTTS
import subprocess
import time
import os
from random_word import RandomWords
from vocabulary.vocabulary import Vocabulary as vb
#Defining some variables and stuff
r = RandomWords()
#this gets the random word and checks if it has a dictionary definition, and makes the audio file
randword = r.get_random_word(hasDictionaryDef="true")
file = randword+' Definition.mp3'
#this part gets the meaning and converts the meaning into a string so it can say the text
todefine = vb.meaning(randword)
texty = str(todefine)
#What makes the text, then plays it
def PlayText():
#this part makes the file
language = 'en'
myobj = gTTS(text=texty, lang=language, slow=False)
myobj.save(file)
time.sleep(1)
#these prints are for debugging, randword is the random word, todefine is the definition
print(randword)
#texty is probably false, unless this has been fixed, and actaully define sthe word.
print(texty)
subprocess.call(file, shell=True)
#this just calls the function where everything is happening
PlayText()
感谢您阅读本文,如果您想提供帮助,非常感谢!
【问题讨论】:
-
当您遇到第三方库的问题时,请务必先查看该库的文档和问题跟踪器。在这种情况下,您似乎在报告一个未解决的问题:github.com/tasdikrahman/vocabulary/issues/70
-
哦,是的,很抱歉标题定义中的错字
-
哦,好的,我不知道,谢谢!
标签: python python-3.x vocabulary