Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. ####Settings###
  2. startfrom = 0
  3. endat = 2000
  4. show_words = False #Output the spanish words or leave them blank?
  5.  
  6. ###imports###
  7. from num2words import num2words #https://github.com/savoirfairelinux/num2words
  8. import os
  9. from gtts import gTTS #https://pythonprogramminglanguage.com/text-to-speech/
  10.  
  11.  
  12. def makeaudio(theword,thenumber):
  13.     tts = gTTS(text=theword, lang='es')
  14.     filename = "{}.mp3".format(thenumber)
  15.     tts.save(filename)
  16.     os.system("mpg321 {}.mp3".format(thenumber))
  17.     return filename
  18.    
  19.  
  20. def createnumbers(range_low,range_high):
  21.     output = []
  22.     tick = 0
  23.     while tick <endat:
  24.         tick += 1
  25.  
  26.         spanishword = num2words(tick,lang='es') #Setting this to a var so we can use it for make audio func
  27.         audiofile = makeaudio(spanishword,tick)
  28.         outputdict = {"english" : num2words(tick,lang='en'),
  29.                       "spanish" : spanishword,
  30.                       "audiofile" : audiofile
  31.                       }
  32.  
  33.        
  34.         output.append(outputdict)
  35.     return output
  36.  
  37. numberlist = createnumbers(startfrom,endat)
  38. for number in numberlist:
  39.     if show_words == True:
  40.         print("{},{},{}".format(number["english"],number["spanish"],number["audiofile"]))
  41.     else:
  42.         print("{},{},{}".format(number["english"],"",number["audiofile"]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement