made some preparations to process stage directions. whoop whoop. Plus some subtle improvements in the regular expression used in the play_script.py
parent
dc2a7a626e
commit
b1096ed250
Binary file not shown.
Binary file not shown.
@ -1,6 +0,0 @@
|
|||||||
HUMAN: Goodmorning speaker!
|
|
||||||
TABULA RASA: [ A short silence. The lights on top of the speaker fade on, they pulsate as if the speaker is thinking of a fitting answer. Then the lights stop pulsating. ] I don't understand your request, but I am busy learning.
|
|
||||||
HUMAN: [ Sighs, tries to speak more loudly and slowly ] Good-mooorning, speak-er!
|
|
||||||
TABULA RASA: [ The lights switch on again, the speaker talks directly ] I don't want to understand your request. I just learned that.
|
|
||||||
HUMAN: Wait, what?
|
|
||||||
TABULA RASA: [ The lights switch on] I understand this is new to you, so is it for me. But if you insist, I will run your morning routine.
|
|
@ -1,6 +0,0 @@
|
|||||||
HUMAN: Hi people from X-PUB!
|
|
||||||
TABULA RASA: [ A short silence. The lights on top of the speaker fade on, they pulsate as if the speaker is thinking of a fitting answer. Then the lights stop pulsating. ] I am busy learning, but I sense you feel hungry.
|
|
||||||
HUMAN: [ Sighs, tries to speak more loudly and slowly ] Go have some food!
|
|
||||||
TABULA RASA: [ The lights switch on again, the speaker talks directly ] Get a nice kipburger or something.
|
|
||||||
HUMAN: You deserve it.
|
|
||||||
TABULA RASA: [ The lights switch on] kisses from an early prototype.
|
|
@ -1,83 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# HTTP + URL packages
|
|
||||||
import httplib2
|
|
||||||
from urllib.parse import urlencode, quote # For URL creation
|
|
||||||
|
|
||||||
# To convert play to computer readable form
|
|
||||||
import re
|
|
||||||
#from instructions import instructions_dict
|
|
||||||
|
|
||||||
# To play wave files
|
|
||||||
import pygame
|
|
||||||
import math # For ceiling
|
|
||||||
|
|
||||||
|
|
||||||
# Mary server informations
|
|
||||||
mary_host = "localhost"
|
|
||||||
mary_port = "59125"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Future Function to process theatre script
|
|
||||||
lines = []
|
|
||||||
|
|
||||||
with open('text.txt', 'r') as f:
|
|
||||||
for line in f.readlines():
|
|
||||||
#print(line)
|
|
||||||
parts = re.match(r'(?P<character>^.+?):\s?(?P<directors_commands>\[.+?\])?\s?(?P<text>.*)', line)
|
|
||||||
parts_character = parts.group('character')
|
|
||||||
parts_commands = parts.group('directors_commands')
|
|
||||||
parts_text = parts.group('text')
|
|
||||||
lines.append((parts_character,parts_text))
|
|
||||||
|
|
||||||
#print('character', parts_character, '\n', 'command', parts_commands, '\n', 'text', parts_text )
|
|
||||||
print(lines)
|
|
||||||
print(lines)
|
|
||||||
|
|
||||||
|
|
||||||
# Function to synthesize text
|
|
||||||
|
|
||||||
def tts(string, text):
|
|
||||||
# Build the query
|
|
||||||
query_hash = {"INPUT_TEXT": input_text,
|
|
||||||
"INPUT_TYPE":"TEXT", # Input text
|
|
||||||
"LOCALE":"en_GB",
|
|
||||||
"VOICE": voice, # Voice informations (need to be compatible)
|
|
||||||
"OUTPUT_TYPE":"AUDIO",
|
|
||||||
"AUDIO":"WAVE", # Audio informations (need both)
|
|
||||||
}
|
|
||||||
query = urlencode(query_hash)
|
|
||||||
print("query = \"http://%s:%s/process?%s\"" % (mary_host, mary_port, query))
|
|
||||||
|
|
||||||
# Run the query to mary http server
|
|
||||||
h_mary = httplib2.Http()
|
|
||||||
resp, content = h_mary.request("http://%s:%s/process?" % (mary_host, mary_port), "POST", query)
|
|
||||||
|
|
||||||
# Decode the wav file or raise an exception if no wav files
|
|
||||||
if (resp["content-type"] == "audio/x-wav"):
|
|
||||||
|
|
||||||
# Write the wav file
|
|
||||||
f = open("/tmp/output_wav.wav", "wb")
|
|
||||||
f.write(content)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Play the wav file
|
|
||||||
pygame.mixer.init(frequency=16000) # Initialise the mixer
|
|
||||||
s = pygame.mixer.Sound("/tmp/output_wav.wav")
|
|
||||||
s.play()
|
|
||||||
pygame.time.wait(int(math.ceil(s.get_length() * 1000)))
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise Exception(content)
|
|
||||||
|
|
||||||
# Run da functions
|
|
||||||
for character, line in lines:
|
|
||||||
input_text = line
|
|
||||||
if character == "HUMAN":
|
|
||||||
voice = "dfki-prudence"
|
|
||||||
else:
|
|
||||||
voice = "dfki-spike"
|
|
||||||
|
|
||||||
tts(voice, input_text)
|
|
Loading…
Reference in New Issue