Я делаю сценарий, который берет случайное слово и получает определение слова, затем он преобразует его в речь и воспроизводит его, но по какой-то причине, когда я пытаюсь получить определение слова, он просто возвращает 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()
Спасибо, что прочитали это, и если вы пытались помочь, супер спасибо!