text2speech.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import signal
  2. import subprocess
  3. import os
  4. from gi.repository import Gtk
  5. window = Gtk.Window(title="Rose Text to Speech")
  6. window.set_border_width(10)
  7. window.connect("destroy", lambda w: Gtk.main_quit())
  8. hbox = Gtk.Box(spacing=6)
  9. window.add(hbox)
  10. textview = Gtk.TextView()
  11. hbox.pack_start(textview, True, True, 0)
  12. def p(button):
  13. global po
  14. text = textview.get_buffer()
  15. start = text.get_start_iter()
  16. end = text.get_end_iter()
  17. input =text.get_text(start, end, include_hidden_chars=1)
  18. file=open("file", "w+")
  19. print(input, end="", file=file)
  20. fest="festival --tts "
  21. text=fest+"file"
  22. po = subprocess.Popen(text, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
  23. def ex(button1):
  24. exit()
  25. def st(button2):
  26. os.killpg(po.pid, signal.SIGTERM) # Send the signal to all the process groups
  27. button = Gtk.Button.new_with_label("Play")
  28. button.connect("clicked", p)
  29. hbox.pack_start(button, True, True, 0)
  30. button1 = Gtk.Button.new_with_label("Stop")
  31. button1.connect("clicked", st)
  32. hbox.pack_start(button1, True, True, 0)
  33. button2 = Gtk.Button.new_with_label("Exit")
  34. button2.connect("clicked", ex)
  35. hbox.pack_start(button2, True, True, 0)
  36. window.show_all()
  37. Gtk.main()