Guest User

Untitled

a guest
Dec 7th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. # -*- encoding: utf-8 -*-
  2. import win32gui
  3. import win32con
  4. import time
  5.  
  6.  
  7. class VoiceRoidError(Exception):
  8. def __init__(self, reason):
  9. self.reason = reason
  10.  
  11. def __str__(self):
  12. return str(self.reason)
  13.  
  14.  
  15. class VoiceRoid(object):
  16. def __init__(self, name):
  17. self.name = name
  18. self.parentHwnd = win32gui.FindWindow(None, name)
  19.  
  20. if self.parentHwnd == 0:
  21. raise VoiceRoidError("VoiceRoidNotFound")
  22. self.play = self.getHandle(text="再生")[0]
  23. self.textbox = self.getHandle(name="WindowsForms10.RichEdit20W")[0]
  24.  
  25. def getHandle(self, **args):
  26. result = []
  27.  
  28. def enumwindows(hwnd, args):
  29. if not args.get("text", None) is None:
  30. if args["text"] in win32gui.GetWindowText(hwnd):
  31. result.append(hwnd)
  32. elif not args.get("name") is None:
  33. if args["name"] in win32gui.GetClassName(hwnd):
  34. result.append(hwnd)
  35.  
  36. win32gui.EnumChildWindows(
  37. self.parentHwnd,
  38. enumwindows,
  39. args
  40. )
  41. return result
  42.  
  43. def sendText(self, hwnd, text):
  44. win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, 0, text)
  45.  
  46. def say(self, text):
  47. while True:
  48. time.sleep(0.15)
  49. if len(self.getHandle(text="一時停止")) < 1:
  50. break
  51. self.sendText(self.textbox, text)
  52.  
  53. win32gui.SendMessage(self.play, win32con.BM_CLICK, 0, 0)
  54.  
  55. if __name__ == "__main__":
  56. import sys
  57. args = sys.argv
  58. print(args)
  59.  
  60. if 1 < len(args):
  61. voiceroid = VoiceRoid("VOICEROID+ 結月ゆかり EX")
  62. text = args[1]
  63. voiceroid.say(text)
Add Comment
Please, Sign In to add comment