Advertisement
lukethenerd

Untitled

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