Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def text_to_speach(text):
  2.  
  3. with open(join(dirname(__file__),'resources/text.wav'),
  4. 'wb') as audio_file:
  5. audio_file.write(
  6. text_to_speech.synthesize(str(text), accept='audio/wav',
  7. voice="en-US_AllisonVoice"))
  8.  
  9. createjs.Sound.on("fileload", this.loadHandler, this);
  10.  
  11. function loadHandler(event) {
  12. createjs.Sound.play("x");
  13. }
  14.  
  15. socket.onmessage = function(e) {
  16. createjs.Sound.registerSound("resources/text.wav", "x"); // регистрирую файл
  17. loadHandler() // вызываю функцию для воспроизведения
  18. }
  19.  
  20. function initialHandler(event) {
  21. Voice = "resources/" + data.filename + ".wav";
  22. playHandler();
  23. }
  24. function registerHandler() {
  25. createjs.Sound.registerSound(Voice);
  26. createjs.Sound.on("fileload", playHandler);
  27. }
  28. function playHandler() {
  29. if(createjs.Sound.loadComplete(Voice)) {
  30. createjs.Sound.play(Voice);
  31. } else {
  32. registerHandler()
  33. }
  34. }
  35.  
  36. file_path = join(dirname(__file__),'resources/{}.wav'.format(filename))
  37. if not os.path.exists(file_path):
  38. with open(file_path, 'wb') as audio_file:
  39. audio_file.write(
  40. text_to_speech.synthesize(str(text),
  41. accept='audio/wav',
  42. voice="en-US_AllisonVoice")
  43. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement