Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import pyttsx3
  2. import subprocess
  3. import threading
  4. import pydub
  5. import ffmpeg
  6. from time import sleep
  7. from threading import Thread
  8.  
  9.  
  10. # VARIABLES
  11. beat_to_play = 'beat.mp3'
  12. slowdown_rate = 35 # higher value means slower speech... keep it between ~50 and 0 depending on how fast the beat is.
  13. intro = 24 #amount in seconds it takes from the start of the beat to when the rapping should begin... how many seconds the AI waits to start rapping.
  14. lyricfile = 'bino_rap1.txt'
  15.  
  16. def play_mp3(path):
  17. subprocess.Popen([pydub, '-q', path]).wait()
  18.  
  19.  
  20. engine = pyttsx3.init()
  21.  
  22. def letters(input):
  23. valids = []
  24. for character in input:
  25. if character.isalpha() or character == "," or character == "'" or character == " ":
  26. valids.append(character)
  27. return ''.join(valids)
  28.  
  29. lyrics = open(lyricfile).read().split("\n") #this reads lines from a file called 'neural_rap.txt'
  30. #print lyrics
  31. rate = engine.getProperty('rate')
  32. engine.setProperty('rate', 'rate - slowdown_rate')
  33. voices = engine.getProperty('voices')
  34.  
  35. wholesong = ""
  36. for i in lyrics:
  37. wholesong += i + " ... "
  38.  
  39.  
  40. def sing():
  41. for line in wholesong.split(" ... "):
  42. if line == "..." or line == "":
  43. for i in range(18):
  44. engine.say(" ")
  45. else:
  46. engine.say(str(line))
  47. engine.runAndWait()
  48.  
  49. def beat():
  50. play_mp3(beat_to_play)
  51.  
  52.  
  53. Thread(target=beat).start()
  54. sleep(intro) # just waits a little bit to start talking
  55. Thread(target=sing).start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement