0

I am making a script that takes a random word and gets the definition of the word, then it would convert it into speech and play it, but for some reason whenever I try to get the definition of the word it just returns false, is there any way to fix this?

Note: I am using vocabulary to get the definition of the word and random words to get the random word that is going to be defined.

Script:

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()

Thanks for reading this, and if you tried to help, super thanks!

1 Answers1

0

Well, it turns out that vocabulary is actually broken as the API it relies on to get definition cut support from it, so the solution is to actually use something else, like pydictionary, thanks to anyone who tried to help, and have a good day, or night, depending on where you are. Here is the link to the place where I got the info, thanks to Adriaan for giving me this, https://github.com/tasdikrahman/vocabulary/issues/70.

Here is the fixed code:

#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()