diff --git a/corpus.txt b/corpus.txt new file mode 100644 index 0000000..1b8b0b1 --- /dev/null +++ b/corpus.txt @@ -0,0 +1,28 @@ +Thank you for calling Pampers. +How may I help you today? +I understand your frustration and disappointment. +I'm sorry it's happening and I'd like to help prevent it in the future. +What style of Baby Dry did you buy? +Was it the Regular or the Flexible? +I have all the information I need about the specifics of the product you purchased now. +Thank you for your patience! +How many diapers came in the package??? +And what size were they? +Were they the small. The medium or the large ones??? +Sorry, without the size and count information I will be able to reimburse you with only a minimum fulfillment. +Would that be okay?? +So you bought the Pampers Baby Dry and there were 32 diapers in the package. +Is that correct? +Thank you for all that information.' +I will definitely pass on your detailed feedback to our Quality Control Team! +I could also suggest a different variant of diapers, that might better suit your needs. +Would you like me to help you with that????? +How old is your little one? +And do you have specific diaper needs that you can help me with?? +Our cruzers are made especially for active babies, and I would definitely suggest them since you said your little one moves around a lot. +What I can do for you is, I can also include a coupon towards your next purchase of Pampers products. +Shall I go ahead with this? +I can send you a link over text message,,, from which you can directly order this. +Is there anything else I can help you with today? +Thank you for reaching out to us. +Have a good day!!! Bye! diff --git a/final.ipynb b/final.ipynb index cfa431e..29926f3 100644 --- a/final.ipynb +++ b/final.ipynb @@ -2,87 +2,9 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/ubuntu/tacotron2/plotting_utils.py:2: UserWarning: \n", - "This call to matplotlib.use() has no effect because the backend has already\n", - "been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,\n", - "or matplotlib.backends is imported for the first time.\n", - "\n", - "The backend was *originally* set to 'module://ipykernel.pylab.backend_inline' by the following code:\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/runpy.py\", line 193, in _run_module_as_main\n", - " \"__main__\", mod_spec)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/runpy.py\", line 85, in _run_code\n", - " exec(code, run_globals)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/__main__.py\", line 3, in \n", - " app.launch_new_instance()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n", - " app.start()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/kernelapp.py\", line 505, in start\n", - " self.io_loop.start()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/platform/asyncio.py\", line 148, in start\n", - " self.asyncio_loop.run_forever()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/asyncio/base_events.py\", line 438, in run_forever\n", - " self._run_once()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/asyncio/base_events.py\", line 1451, in _run_once\n", - " handle._run()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/asyncio/events.py\", line 145, in _run\n", - " self._callback(*self._args)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/ioloop.py\", line 690, in \n", - " lambda f: self._run_callback(functools.partial(callback, future))\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n", - " ret = callback()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/gen.py\", line 781, in inner\n", - " self.run()\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/gen.py\", line 742, in run\n", - " yielded = self.gen.send(value)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n", - " yield gen.maybe_future(dispatch(*args))\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/gen.py\", line 209, in wrapper\n", - " yielded = next(result)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n", - " yield gen.maybe_future(handler(stream, idents, msg))\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/gen.py\", line 209, in wrapper\n", - " yielded = next(result)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n", - " user_expressions, allow_stdin,\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/tornado/gen.py\", line 209, in wrapper\n", - " yielded = next(result)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n", - " res = shell.run_cell(code, store_history=store_history, silent=silent)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n", - " return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n", - " raw_cell, store_history, silent, shell_futures)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n", - " return runner(coro)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n", - " coro.send(None)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n", - " interactivity=interactivity, compiler=compiler, result=result)\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n", - " if (yield from self.run_code(code, result)):\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n", - " exec(code_obj, self.user_global_ns, self.user_ns)\n", - " File \"\", line 3, in \n", - " import matplotlib.pylab as plt\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/matplotlib/pylab.py\", line 257, in \n", - " from matplotlib import cbook, mlab, pyplot as plt\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/matplotlib/pyplot.py\", line 69, in \n", - " from matplotlib.backends import pylab_setup\n", - " File \"/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/matplotlib/backends/__init__.py\", line 14, in \n", - " line for line in traceback.format_stack()\n", - "\n", - "\n", - " matplotlib.use(\"Agg\")\n" - ] - } - ], + "outputs": [], "source": [ "import matplotlib\n", "#%matplotlib inline\n", @@ -106,7 +28,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -115,37 +37,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.\n", - "For more information, please see:\n", - " * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md\n", - " * https://github.com/tensorflow/addons\n", - "If you depend on functionality not listed there, please file an issue.\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class 'glow.WaveGlow' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n", - " warnings.warn(msg, SourceChangeWarning)\n", - "/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class 'torch.nn.modules.conv.ConvTranspose1d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n", - " warnings.warn(msg, SourceChangeWarning)\n", - "/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class 'glow.WN' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n", - " warnings.warn(msg, SourceChangeWarning)\n", - "/home/ubuntu/anaconda3/envs/tts/lib/python3.6/site-packages/torch/serialization.py:454: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv1d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n", - " warnings.warn(msg, SourceChangeWarning)\n" - ] - } - ], + "outputs": [], "source": [ "hparams = create_hparams()\n", "hparams.sampling_rate = 22050\n", @@ -163,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -172,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -181,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -198,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -223,32 +117,58 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "speech('I understand your frustration and disappointment. I am sorry that its happening and I would like to help prevent it in the future. What style of diapers did you buy? For instance, was it the snugglers, pull ups or baby dry.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "from final import display,speech,play_device\n", + "import pyaudio" + ] + }, + { + "cell_type": "code", + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[46 11 58 51 41 42 55 56 57 38 51 41 11 62 52 58 55 11 43 55 58 56 57 55\n", - " 38 57 46 52 51 11 38 51 41 11 41 46 56 38 53 53 52 46 51 57 50 42 51 57\n", - " 7 11 46 11 38 50 11 56 52 55 55 62 11 57 45 38 57 11 46 57 56 11 45 38\n", - " 53 53 42 51 46 51 44 11 38 51 41 11 46 11 60 52 58 49 41 11 49 46 48 42\n", - " 11 57 52 11 45 42 49 53 11 53 55 42 59 42 51 57 11 46 57 11 46 51 11 57\n", - " 45 42 11 43 58 57 58 55 42 7 11 60 45 38 57 11 56 57 62 49 42 11 52 43\n", - " 11 41 46 38 53 42 55 56 11 41 46 41 11 62 52 58 11 39 58 62 10 11 43 52\n", - " 55 11 46 51 56 57 38 51 40 42 6 11 60 38 56 11 46 57 11 57 45 42 11 56\n", - " 51 58 44 44 49 42 55 56 6 11 53 58 49 49 11 58 53 56 11 52 55 11 39 38\n", - " 39 62 11 41 55 62 7]]\n", - "21.24711561203003\n" + "15.046638011932373\n" ] - }, + } + ], + "source": [ + "data = speech('Thank you for calling Huggies. How may I help you today .')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ { "data": { "text/html": [ "\n", " \n", " " @@ -257,33 +177,28 @@ "" ] }, - "execution_count": 11, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "speech('I understand your frustration and disappointment. I am sorry that its happening and I would like to help prevent it in the future. What style of diapers did you buy? For instance, was it the snugglers, pull ups or baby dry.')" + "display(data)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 16, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'sequence' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msequence\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'sequence' is not defined" - ] - } - ], - "source": [] + "outputs": [], + "source": [ + "def play_device(data):\n", + " audio_interface = pyaudio.PyAudio()\n", + " _audio_stream = audio_interface.open(format=pyaudio.paInt16,channels=1, rate=16000,output=True)\n", + " _audio_stream.write(data.tostring())\n", + "# _audio_stream.close()\n", + "play_device(data)" + ] }, { "cell_type": "code", diff --git a/final.py b/final.py index b27ffa4..31d63b7 100644 --- a/final.py +++ b/final.py @@ -19,6 +19,8 @@ from text import text_to_sequence import os import soundfile as sf import pyaudio +import klepto +import IPython.display as ipd import time sys.path.append('waveglow/') @@ -34,6 +36,7 @@ waveglow = torch.load(waveglow_path, map_location='cpu')['model'] waveglow.eval() for k in waveglow.convinv: k.float() +k_cache = klepto.archives.file_archive(cached=False) # https://github.com/NVIDIA/waveglow/issues/127 for m in waveglow.modules(): @@ -43,13 +46,15 @@ for m in waveglow.modules(): def convert(array): sf.write('sample.wav', array, 22050) - os.system('ffmpeg -i {0} -filter:a "atempo=0.80" -ar 16k {1}'.format('sample.wav', 'sample0.wav')) + os.system('ffmpeg -i {0} -filter:a "atempo=0.80" -ar 16k {1}'.format( + 'sample.wav', 'sample0.wav')) data, rate = sf.read('sample0.wav', dtype='int16') os.remove('sample.wav') os.remove('sample0.wav') return data +@klepto.safe.inf_cache(cache=k_cache) def speech(t): start = time.time() text = t @@ -67,12 +72,53 @@ def speech(t): return data -def main(): - data = speech('Hi I am Sia How may I help you today'.lower()) +def display(data): + aud = ipd.Audio(data, rate=16000) + return aud + + +def player_gen(): audio_interface = pyaudio.PyAudio() - _audio_stream = audio_interface.open(format=pyaudio.paInt16,channels=1, rate=16000,output=True) - _audio_stream.write(data) - import pdb; pdb.set_trace() + _audio_stream = audio_interface.open(format=pyaudio.paInt16, + channels=1, + rate=16000, + output=True) + + def play_device(data): + _audio_stream.write(data.tostring()) + # _audio_stream.close() + + return play_device + + +def synthesize_corpus(): + all_data = [] + for line in open('corpus.txt').readlines(): + print('synthesizing... "{}"'.format(line.strip())) + data = speech(line.strip()) + all_data.append(data) + return all_data + + +def play_corpus(corpus_synths): + player = player_gen() + for d in corpus_synths: + player(d) + + +def main(): + # data = speech('Hi I am Sia. How may I help you today .'.lower()) + # audio_interface = pyaudio.PyAudio() + # _audio_stream = audio_interface.open(format=pyaudio.paInt16, + # channels=1, + # rate=16000, + # output=True) + # _audio_stream.write(data) + corpus_synth_data = synthesize_corpus() + play_corpus(corpus_synth_data) + import ipdb + ipdb.set_trace() + if __name__ == '__main__': main()