forked from robbiebarrat/rapping-neural-network
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechtest.py
More file actions
37 lines (27 loc) · 825 Bytes
/
Copy pathspeechtest.py
File metadata and controls
37 lines (27 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pyttsx
import subprocess
import threading
import string
from time import sleep
from threading import Thread
def play_mp3(path):
subprocess.Popen(['mpg123', '-q', path]).wait()
engine = pyttsx.init()
lyrics = open("neural_rap.txt").read().split("\n") #this reads lines from a file called 'neural_rap.txt'
rate = engine.getProperty('rate')
engine.setProperty('rate', rate - 30)
voices = engine.getProperty('voices')
wholesong = ""
for i in lyrics:
wholesong += i
wholesong += " ... ... "
printable = set(string.printable)
def sing():
for i in lyrics:
engine.say(str(filter(lambda x: x in printable, wholesong)))
engine.runAndWait()
def beat():
play_mp3("beat.mp3")
Thread(target=beat).start()
sleep(14) # just waits a little bit to start talking
Thread(target=sing).start()