【问题标题】:Is There A Way To Not Get False For The Defintion Of A Word With The Vocabulary Module?有没有办法不让词汇模块的单词定义出错?
【发布时间】: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


【解决方案1】:

好吧,事实证明,词汇表实际上是被破坏的,因为它依赖于从它那里获得定义切割支持的 API,所以解决方案是实际使用其他东西,比如 pydictionary,感谢任何试图提供帮助的人,并且有美好的一天,还是美好的夜晚,取决于你在哪里。这是我获得信息的地方的链接,感谢 Adriaan 给我这个,https://github.com/tasdikrahman/vocabulary/issues/70

这里是固定代码:

#The things i import
from gtts import gTTS
import subprocess
import time
import os
from random_word import RandomWords
from PyDictionary import PyDictionary
#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
dictionary=PyDictionary()
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 = dictionary.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()

【讨论】:

    猜你喜欢
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    相关资源
    最近更新 更多