Browse Source

Overrule main gitignore

master
Alberto Pettarin 8 years ago
parent
commit
e9fc02cbc1
3 changed files with 259 additions and 0 deletions
  1. 2
    0
      emscripten/.gitignore
  2. 139
    0
      emscripten/Makefile
  3. 118
    0
      emscripten/demo.html

+ 2
- 0
emscripten/.gitignore View File

@@ -5,3 +5,5 @@ espeakng_data_package.js
glue.*
espeakng.worker.*
pthread-main.js
!demo.html
!Makefile

+ 139
- 0
emscripten/Makefile View File

@@ -0,0 +1,139 @@
#
# Copyright (C) 2014-2016 Eitan Isaacson
# Copyright (C) 2016 Alberto Pettarin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see: <http://www.gnu.org/licenses/>.
#

# NOTE: variables specific to espeak-ng + emscripten starts with "EM_"

# NOTE: set to 1 to debug or to speed emscripten up while developing.
# If the EM_DEBUG environment variable is set,
# the value specified here will be ignored.
EM_DEBUG ?= 0
ifneq ($(EM_DEBUG), 1)
CXXFLAGS+=-O3
endif



###############################################################################
# WARNING: modify code below this line at your own risk!
###############################################################################

# NOTE: sanity check
ifndef EMSCRIPTEN
$(error EMSCRIPTEN var not set. You must use emmake to run this Makefile!)
endif

# NOTE: in the emscripten virtual FS,
# this is the location of the eSpeak-ng data files,
# if we configure with "./configure --prefix=/usr"
EM_VIRTUAL_PATH_ESPEAKNG_DATA=/usr/share/espeak-ng-data

# NOTE: emmake will replace EMSCRIPTEN with the actual root directory
# of the emscripten tools inside the emscripten SDK directory
EM_WEBIDL_BINDER=python $(EMSCRIPTEN)/tools/webidl_binder.py
EM_FILE_PACKAGER=python $(EMSCRIPTEN)/tools/file_packager.py

# NOTE: libespeak-ng.so compiled to LLVM IR code
EM_LIBESPEAKNG_SO=../src/.libs/libespeak-ng.so

# NOTE: glue code files
EM_GLUE_PREFIX=glue
EM_GLUE_IDL=espeakng_glue.idl
EM_GLUE_OBJ=espeakng_glue.o
EM_GLUE_CPP=espeakng_glue.cpp
EM_GLUE_AUTOGEN_CPP=glue.cpp
EM_GLUE_AUTOGEN_JS=glue.js

# NOTE: preload espeak-ng-data directory...
EM_DATA_DIR=../espeak-ng-data
# NOTE: ... but exclude these subdirectories/files
EM_EXCLUDE_DATA=../espeak-ng-data/mbrola_ph ../espeak-ng-data/phondata-manifest

# NOTE: pre/post JS files
EM_PRE_JS=pre.js
EM_POST_JS=post.js

# NOTE: output files
EM_ESPEAKNG_DATA_PACKAGE_JS=espeakng_data_package.js
EM_WORKER_DATA=js/espeakng.worker.data
EM_WORKER_JS=js/espeakng.worker.js
EM_PTHREAD_MAIN_JS=js/pthread-main.js

# NOTE: intermediate objects
EM_OBJS=$(EM_GLUE_OBJ) $(EM_LIBESPEAKNG_SO)
EM_ALL_PRE_JS=$(EM_PRE_JS) $(EM_ESPEAKNG_DATA_PACKAGE_JS)
EM_ALL_POST_JS=$(EM_GLUE_AUTOGEN_JS) $(EM_POST_JS)

# NOTE: compile without async, i.e. with synchronous output
#
# ./emconfigure ./configure --prefix=/usr --without-async
# ./emmake make
CXXFLAGS+=-DESPEAK_DATA_PATH=\"$(EM_VIRTUAL_PATH_ESPEAKNG_DATA)\"
CXXFLAGS+=-I ./ -I ../ -I ../src/include/espeak-ng

# NOTE: so far, pthread is not supported in any browser
# except Firefox Nightly.
# If we want to enable pthread in the future,
# we must append "-s USE_PTHREADS=1" to CXXFLAGS
# and pass that to emconfigure and emmake.
# If enabled, js/pthread-main.js will be created as well.
#
#CXXFLAGS+=-s USE_PTHREADS=1

# NOTE: extra flags for emscripten
EM_CXXFLAGS=-s RESERVED_FUNCTION_POINTERS=2 --memory-init-file 0



###############################################################################
# NOTE: actual targets
###############################################################################

all: $(EM_WORKER_JS)

$(EM_WORKER_DATA):
$(EM_FILE_PACKAGER) $@ \
--js-output=$(EM_ESPEAKNG_DATA_PACKAGE_JS) \
--preload $(EM_DATA_DIR)@$(EM_VIRTUAL_PATH_ESPEAKNG_DATA) \
$(patsubst %,--exclude %,$(EM_EXCLUDE_DATA))

$(EM_ESPEAKNG_DATA_PACKAGE_JS): $(EM_WORKER_DATA)

$(EM_GLUE_AUTOGEN_CPP): $(EM_GLUE_IDL)
$(EM_WEBIDL_BINDER) $(EM_GLUE_IDL) $(EM_GLUE_PREFIX)

$(EM_GLUE_AUTOGEN_JS): $(EM_GLUE_AUTOGEN_CPP)

$(EM_GLUE_OBJ): $(EM_GLUE_CPP)

$(EM_WORKER_JS): $(EM_GLUE_AUTOGEN_CPP) $(EM_OBJS) $(EM_ALL_PRE_JS) $(EM_ALL_POST_JS)
$(CXX) $(CXXFLAGS) \
$(EM_CXXFLAGS) \
$(EM_OBJS) \
$(patsubst %,--pre-js %,$(EM_ALL_PRE_JS)) \
$(patsubst %,--post-js %,$(EM_ALL_POST_JS)) \
-o $@

clean-intermediate:
rm -f *.o *.out *.pkl $(EM_GLUE_AUTOGEN_CPP) $(EM_GLUE_AUTOGEN_JS) $(EM_ESPEAKNG_DATA_PACKAGE_JS)

clean: clean-intermediate
rm -f $(EM_WORKER_DATA) $(EM_WORKER_JS) $(EM_PTHREAD_MAIN_JS)

help:
echo "Available targets: all clean clean-intermediate help"


+ 118
- 0
emscripten/demo.html View File

@@ -0,0 +1,118 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<title>espeakng.js Demo</title>
<style>
h1 {
max-width: 480px;
margin: 2rem auto;
font-size: 150%;
}
form {
max-width: 480px;
margin: 0 auto;
}
.speecharg label {
display: inline-block;
width: 20%;
}
.speecharg input, .speecharg select {
display: inline-block;
width: calc(80% - 3rem);
margin: 0;
}
.speecharg button {
width: 1.5rem;
height: 1.5rem;
margin: 0 0 0 1.5rem;
display: inline-block;
}
.bottom {
margin-top: 1rem;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
margin: 1rem 0;
}
.bottom button {
flex-grow: 1;
-webkit-flex-grow: 1;
}
#texttospeak {
width: 100%;
height: 8rem;
display: block;
margin-bottom: 1rem;
}
p.gh {
color: #333;
text-align: right;
display: block;
font-style: italic;
}

/* loading screen */
#splash {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #fff;
padding-top: 4rem;
transition: opacity 200ms ease, visibility 200ms;
-webkit-transition: opacity 200ms ease, visibility 200ms;
visibility: hidden;
opacity: 0;
}
body.loading #splash {
visibility: visible;
opacity: 1;
}
#splash > * {
width: 10rem;
max-width: 480px;
margin: 2rem auto;
display: block;
text-align: center;
}
body.loading > *:not(#splash) {
visibility: hidden;
}

</style>
<script type="text/javascript" src="js/espeakng.js"></script>
<script type="text/javascript" src="js/demo.js"></script>
</head>
<body class="loading">
<div id="splash">
<div>Loading eSpeak-ng worker and data...</div>
<progress></progress>
</div>
<h1>espeakng.js Demo</h1>
<form>
<textarea id="texttospeak">Call me Ishmael. Some years ago --- never mind how long precisely --- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation.</textarea>
<div class="speecharg">
<label for="pitch">Pitch</label><input id="pitch" type="range" value="50" min="0" max="100"><button type="button" aria-label="Reset pitch" title="Reset pitch" onclick="resetPitch();">&#x21b6;</button>
</div>
<div class="speecharg">
<label for="rate">Rate</label><input id="rate" type="range" value="175" min="80" max="450"><button type="button" aria-label="Reset rate" title="Reset rate" onclick="resetRate();">&#x21b6;</button>
</div>
<div class="speecharg">
<label for="voice">Voice</label><select id="voice"></select><button type="button" aria-label="Reset voice" title="Reset voice" onclick="resetVoice();">&#x21b6;</button>
</div>
<div class="bottom">
<button type="button" onmousedown="speak();">Speak</button>
<button type="button" onmousedown="stop();">Stop</button>
</div>
<p class="gh"><a href="https://github.com/eeejay/espeak/tree/emscripten">Original Code for eSpeak: Eitan Isaacson</a></p>
<p class="gh"><a href="https://github.com/pettarin/espeak-ng/tree/emscripten">Adapted Code for eSpeak-ng: Alberto Pettarin</a></p>
</form>
<script type="text/javascript">
initializeDemo();
</script>
</body>
</html>

Loading…
Cancel
Save