tts2.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import pyttsx3
  2. import rpyc
  3. import random
  4. import time
  5. import sys
  6. import codecs
  7. engine = pyttsx3.init()
  8. #engine.say("I will speak this text")
  9. #engine.save_to_file("中文測試,我會講中文", 'test.mp3')
  10. engine.setProperty('rate',175)
  11. fr=codecs.open('/tmp/script.txt','r','u-tf8')
  12. lines=fr.readlines()
  13. fr.close()
  14. engine.say("你好,我是,集仕多股份有限公司,開發的,人工智慧主播,這是一個測試影片。我們與幸福空間合作,只要給我們影片的腳本文字檔案,我們立刻可以產生影片。", 'test.mp3')
  15. engine.runAndWait()
  16. sys.exit()
  17. fr=open('test.mp3','rb')
  18. fw=conn.builtins.open('/tmp/ok2.mp3','wb')
  19. while True:
  20. b=fr.read(1024)
  21. if b:
  22. fw.write(b)
  23. else:
  24. break
  25. fr.close()
  26. fw.close()
  27. val=random.randint(1000000,9999999)
  28. ros.chdir('/home/jared/Wav2Lip-master')
  29. ros.system('./proc.sh '+str(val)+' &')
  30. while True:
  31. print('waiting...')
  32. if ros.path.exists('/tmp/results/'+str(val)):
  33. break
  34. time.sleep(5)
  35. print('waiting...')
  36. fr=conn.builtins.open('/home/jared/Wav2Lip-master/results/result_voice.mp4','rb')
  37. fw=open('result.mp4','wb')
  38. while True:
  39. b=fr.read(1024)
  40. if b:
  41. fw.write(b)
  42. else:
  43. break
  44. fr.close()
  45. fw.close()