Exemple #1
0
def common_words_method(language_full, language):
    welcome = (
        "Welcome to the common words section. We are going to learn the %s translation of ten most common english words"
    ) % (language_full)
    print(welcome)

    f = open('data.txt', 'r')
    random_indices = []
    for i in range(5):
        random_indices.append(random.randint(1, 3001))
    #print(f[0],f[1])
    line_number = 1
    eng = []
    esp = []
    for line in f:
        if (line_number in random_indices):
            eng.append(line)
            tran = translate_text_to_foreign(line, language)
            esp.append(tran)
            print(line + "->" + tran)
            line_object_english = TextToSpeech(line, "en")
            line_object = TextToSpeech(tran, language)
            line_object_english.speech()
            line_object.speech()
            print(" ")
        line_number += 1

    print("Finally the words with their translations are- ")
    for i in range(len(eng)):
        print(eng[i], esp[i])
Exemple #2
0
print("How do you want to learn today?")
print(" ")
selector=input(("Enter 1 for translation help. Enter 2 to see the most used words translated for you. Enter 3 for a fun quiz. Enter 4 to hear %s pronunciation of  specific words: ")%(language_full_name))

if(selector=="1"):
    fine_selector=input(("Enter 0 to translate from english to %s. Enter 1 to translate from %s to english: ")%(language_full_name,language_full_name))
    if(fine_selector=="0"):
        times=int(input("Number of sentences to be translated: "))
        for i in range(times):
            text=(input(("Enter text to be translated to %s: ")%(language_full_name)))

        
            translation =translate_text_to_foreign(text,language_to_be_learnt)
            print("The translation is %s"%(translation))
            speech_object = TextToSpeech(translation,language_to_be_learnt)
            speech_object.speech()
            print(" ")
            if(i==times-1):
                print("Thanks!!")
               

    else:
        times=int(input("Number of sentences to be translated: "))
        for i in range(times):
            text=(input("Enter text to be translated to english: "))

            #language_to_be_learnt="English"
            translation =translate_text_to_english(text,language_to_be_learnt)
            print("The translation is %s"%(translation))
            speech_object = TextToSpeech(translation,"en")
            speech_object.speech()