From b1096ed25063607ce47af0b7e45ab66558c51e02 Mon Sep 17 00:00:00 2001 From: Joca Date: Mon, 18 Mar 2019 17:45:28 +0100 Subject: [PATCH] made some preparations to process stage directions. whoop whoop. Plus some subtle improvements in the regular expression used in the play_script.py --- .../__pycache__/instructions.cpython-35.pyc | Bin 0 -> 260 bytes .../__pycache__/instructions.cpython-36.pyc | Bin 0 -> 252 bytes mary_tts_script/instructions.py | 5 +- mary_tts_script/play_script.py | 11 +-- mary_tts_script/text.txt | 6 -- mary_tts_script/text02.txt | 6 -- mary_tts_script/text2wav.py | 83 ------------------ 7 files changed, 10 insertions(+), 101 deletions(-) create mode 100644 mary_tts_script/__pycache__/instructions.cpython-35.pyc create mode 100644 mary_tts_script/__pycache__/instructions.cpython-36.pyc delete mode 100644 mary_tts_script/text.txt delete mode 100644 mary_tts_script/text02.txt delete mode 100644 mary_tts_script/text2wav.py diff --git a/mary_tts_script/__pycache__/instructions.cpython-35.pyc b/mary_tts_script/__pycache__/instructions.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b45883c1c72d2e3f7d662f8c20faa1e5301af9dc GIT binary patch literal 260 zcmX|6u};G<5IxdHLP1#=m>9ZN2n;(y7%?zFhlVZ@Qe@djdz9GL*%^|b;5*p)ny&l> zEVxB*y7%<-PI^ywRF=ib$J^640DLC=&p4^;gm9e5q}>CPff)g1Py-M^ot!aL)4a~_ z77ubZl;(L&r=B~5R^xE+C~p?`ax#~d9E#m7cv|CZnr#ZbQmk}D4s~IOQAct%yaQ*c zZbx60Sh*I(i_=QnI^DHsV-V*T6VEQX*n6@|v1DbMKLdkk757byp$VGFM?p43?tatH Ve81VhY@O*|@hac`wkk`e(jW7ifq~&M5W@j8kmUfx#X>+Lg&~D8g=r2`6hkIM6k`f=FoPyb6>myf zcBXDYQE5tQUUF&`7noaIkeQvT$rQ!v5$fycSH&IT=oISXs1W2B?C7V-bc-uFBe5tk zxg@oyIEpJJvnVyWBr`v+cqKy-6VMtk@hezABR@A)KPx{uQQsv$ximL5ucTPtz)+!} zD8D4Xq_QA0FI_*qC^01-CXiaJpPN`z8DCOT9ABJVlvz-spP5%&Qd9~tU9X_>7Kcr4 ReoARhsvRrHPaw;^.+?):\s?(?P\[.+?\])?\s?(?P.*)', line) + parts = re.match(r'(?P^.+?):\s?(\[(?P[^]]+)\])?\s?(?P.*)', line) parts_character = parts.group('character') - parts_directions = parts.group('stage_directions') parts_text = parts.group('text') - lines.append((parts_character,parts_text)) + parts_directions = str(parts.group('stage_directions')).split(".") + + lines.append((parts_character,parts_text,parts_directions)) print(lines) return lines; @@ -73,8 +74,8 @@ def tts(string, text): # RUN THE PLAY -for character, line in read_script('text.txt'): +for character, line, directions in read_script('plays/text.txt'): input_text = line voice = characters.get(character) - + # Some way to do something with the stage directions will come here tts(voice, input_text) diff --git a/mary_tts_script/text.txt b/mary_tts_script/text.txt deleted file mode 100644 index d6e4145..0000000 --- a/mary_tts_script/text.txt +++ /dev/null @@ -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. diff --git a/mary_tts_script/text02.txt b/mary_tts_script/text02.txt deleted file mode 100644 index cc81f1a..0000000 --- a/mary_tts_script/text02.txt +++ /dev/null @@ -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. diff --git a/mary_tts_script/text2wav.py b/mary_tts_script/text2wav.py deleted file mode 100644 index 4eda25a..0000000 --- a/mary_tts_script/text2wav.py +++ /dev/null @@ -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^.+?):\s?(?P\[.+?\])?\s?(?P.*)', 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)