Advertisement
skip420

Text2Speech

Aug 12th, 2021
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. # importing required module
  2. from tkinter import *
  3. from gtts import gTTS
  4.  
  5. # this module helps to
  6. # play the converted audio  
  7. import os
  8.  
  9. # create tkinter window
  10. root = Tk()
  11.  
  12. # styling the frame which helps to  
  13. # make our background stylish
  14. frame1 = Frame(root,
  15.                bg = "Red",
  16.                height = "150")
  17.  
  18. # plcae the widget in gui window
  19. frame1.pack(fill = X)
  20.  
  21.  
  22. frame2 = Frame(root,
  23.                bg = "blue",
  24.                height = "750")
  25. frame2.pack(fill=X)
  26.  
  27.  
  28.  
  29. # styling the label which show the text  
  30. # in our tkinter window
  31. label = Label(frame1, text = "Text to Speech",
  32.               font = "bold, 30",
  33.               bg = "lightpink")
  34.  
  35. label.place(x = 180, y = 70)
  36.  
  37.  
  38.  
  39. # entry is used to enter the text  
  40. entry = Entry(frame2, width = 45,
  41.               bd = 4, font = 14)
  42.  
  43. entry.place(x = 130, y = 52)
  44. entry.insert(0, "")
  45.  
  46. # define a function which can
  47. # get text and convert into audio
  48. def play():
  49.  
  50.     # Language in which you want to convert  
  51.     language = "en"
  52.  
  53.  
  54.  
  55.    # Passing the text  and language,  
  56.    # here we have  slow=False. Which tells  
  57.    # the module that the converted audio should  
  58.    # have a high speed  
  59.  
  60.     myobj = gTTS(text = entry.get(),
  61.                 lang = language,
  62.                 slow = False)
  63.  
  64.  
  65.  
  66.     # give the name as you want to  
  67.     # save the audio
  68.     myobj.save("convert.wav")
  69.     os.system("convert.wav")
  70.  
  71. # cereate a button which holds
  72. # our play function using command = play
  73. btn = Button(frame2, text = "SUBMIT",
  74.              width = "15", pady = 10,
  75.              font = "bold, 15",
  76.              command = play, bg='yellow')
  77.  
  78. btn.place(x = 250,
  79.           y = 130)
  80.  
  81. # give a title  
  82. root.title("text_to_speech_convertor")
  83.  
  84.  
  85.  
  86. # we can not change the size
  87. # if you want you can change
  88. root.geometry("650x550+350+200")
  89.  
  90. # start the gui
  91. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement