GithubHelp home page GithubHelp logo

piper-wasm's Introduction

piper-wasm

WASM version of piper powering piper.wide.video.

Build WASM

Build takes ~5 minutes.

# Docker (optional)
docker run -it -v $(pwd):/wasm -w /wasm debian:11.3
apt-get update
apt-get install --yes --no-install-recommends build-essential cmake ca-certificates curl pkg-config git python3 autogen automake autoconf libtool

# Emscripten
git clone --depth 1 https://github.com/emscripten-core/emsdk.git /wasm/modules/emsdk
cd /wasm/modules/emsdk
./emsdk install 3.1.47
./emsdk activate 3.1.47
source ./emsdk_env.sh
TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
sed -i -E 's/int\s+(iswalnum|iswalpha|iswblank|iswcntrl|iswgraph|iswlower|iswprint|iswpunct|iswspace|iswupper|iswxdigit)\(wint_t\)/\/\/\0/g' ./upstream/emscripten/cache/sysroot/include/wchar.h

# espeak-ng
git clone --depth 1 https://github.com/rhasspy/espeak-ng.git /wasm/modules/espeak-ng
cd /wasm/modules/espeak-ng
./autogen.sh
./configure
make

# piper-phonemize
git clone --depth 1 https://github.com/wide-video/piper-phonemize.git /wasm/modules/piper-phonemize
cd /wasm/modules/piper-phonemize
emmake cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE -DBUILD_TESTING=OFF -G "Unix Makefiles" -DCMAKE_CXX_FLAGS="-O3 -s INVOKE_RUN=0 -s MODULARIZE=1 -s EXPORT_NAME='createPiperPhonemize' -s EXPORTED_FUNCTIONS='[_main]' -s EXPORTED_RUNTIME_METHODS='[callMain, FS]' --preload-file /wasm/modules/espeak-ng/espeak-ng-data@/espeak-ng-data"
emmake cmake --build build --config Release # fails on "Compile intonations / Permission denied", continue with next steps
sed -i 's+$(MAKE) $(MAKESILENT) -f CMakeFiles/data.dir/build.make CMakeFiles/data.dir/build+#\0+g' /wasm/modules/piper-phonemize/build/e/src/espeak_ng_external-build/CMakeFiles/Makefile2
sed -i 's/using namespace std/\/\/\0/g' /wasm/modules/piper-phonemize/build/e/src/espeak_ng_external/src/speechPlayer/src/speechWaveGenerator.cpp
emmake cmake --build build --config Release

Following artifacts are created in /wasm/modules/piper-phonemize/build/

  • piper_phonemize.data
  • piper_phonemize.js
  • piper_phonemize.wasm

Build piper-phonemize (native) not required step

git clone https://github.com/rhasspy/piper-phonemize.git
docker buildx build . -t piper-phonemize --output 'type=local,dest=dist'
# unpack ./dist/piper-phonemize_arm64.tar.gz into ./dist/piper_phonemize
# copy ./dist/piper_phonemize/lib/* to ./dist/piper_phonemize/bin
cd ./dist/piper_phonemize
docker run -it -v $(pwd):/piper-phonemize -w /piper-phonemize debian:11.3 
echo "Hello" | ./bin/piper_phonemize -l en-us --espeak-data ./share/espeak-ng-data
# {"phoneme_ids":[1,0,20,0,59,0,24,0,120,0,27,0,100,0,2],"phonemes":["h","ə","l","ˈ","o","ʊ"],"processed_text":"Hello","text":"Hello"}

Docker Reattach

Reattach stdin for exited container:

docker ps -q -l              # find container ID (or discover via Docker desktop)
docker start e24313a5d869    # restart in the background
docker attach e24313a5d869   # reattach the terminal & stdin

piper-wasm's People

Contributors

jozefchutka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gyroing graham83

piper-wasm's Issues

Output raw

Hi
I wonder is it any solution to stdout audiobuffer as stream with --output_raw option and handle it with javascript Dom?

Export d.ts files

How to export typescript definitions of the compiled module?

An example using emcc: emcc -lembind quick_example.cpp --emit-tsd interface.d.ts

Export to es6

It's possible to compile the code to es6 (.mjs) ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.