Skip to content

Commit

Permalink
feat: preliminary open sourcing of desktop_app
Browse files Browse the repository at this point in the history
  • Loading branch information
towc committed Jul 14, 2023
1 parent 56d582d commit 344ab65
Show file tree
Hide file tree
Showing 56 changed files with 27,577 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.vscode
**/*.DS_Store
**/*.code-workspace
**/*.pickle
**/*.pyc
**/__pycache__
**/*.tfevents.*
**/*.mp3
**/*.wav
**/*.zip
**/wandb
**/node_modules
**/build
**/dist
**/*.egg-info
**/Makefile.variable


# Logs
**/logs
**/*.log
**/npm-debug.log*
**/yarn-debug.log*
**/ yarn-error.log*
**/firebase-debug.log*
**/firebase-debug.*.log*

# Firebase cache
**/.firebase/

# Firebase config


# Runtime data
**/pids
**/*.pid
**/*.seed
**/*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
**/lib-cov

# Coverage directory used by tools like istanbul
**/coverage

# nyc test coverage
**/.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
**/.grunt

# Bower dependency directory (https://bower.io/)
**/bower_components

# node-waf configuration
**/.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
**/build/Release

# Optional npm cache directory
**/.npm

# Optional eslint cache
**/.eslintcache

# Optional REPL history
**/.node_repl_history

# Output of 'npm pack'
**/*.tgz

# Yarn Integrity file
**/.yarn-integrity

# dotenv environment variables file
**/.env
188 changes: 188 additions & 0 deletions services/desktop_app/LICENCE.txt

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions services/desktop_app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
include ${METAVOICECODE_ROOT}/Makefile.variable

clean-server:
rm -rf dist/ pyinstallerbuild/

build-server-mac: clean-server
# NOTE: for Librosa, PyInstaller tries to find all the dependencies, however this folder is not imported but loaded so it misses it.
# We include it in the application bundle through --add-data
# TODO sidroopdaska: remove copying over model once lazy loading has been implemented
pyinstaller -D -n metavoice --workpath pyinstallerbuild \
-p ${METAVOICECODE_ROOT} \
--add-data=${SITE_PACKAGES}/librosa/util/example_data:librosa/util/example_data \
--add-data=${SITE_PACKAGES}/_soundfile_data:_soundfile_data \
--add-data=${METAVOICECODE_ROOT}/ai:ai \
server/main.py

echo local > dist/metavoice/version.txt

build-server-windows: clean-server
# NOTE: for Librosa, PyInstaller tries to find all the dependencies, however this folder is not imported but loaded so it misses it.
# We include it in the application bundle through --add-data
# TODO sidroopdaska: remove copying over model once lazy loading has been implemented
pyinstaller -D -n metavoice --workpath pyinstallerbuild \
-p ${METAVOICECODE_ROOT} \
--add-data="${SITE_PACKAGES}/librosa/util/example_data;librosa/util/example_data" \
--add-data="${SITE_PACKAGES}/_soundfile_data;_soundfile_data" \
--add-data="${METAVOICECODE_ROOT}/ai;ai" \
server/main.py

rm -rf dist/metavoice/ai/spectrogram_conversion/saved_models
rm -rf dist/metavoice/ai/spectrogram_conversion/originals
rm -rf dist/metavoice/ai/studio_models/model.mlpackage

echo local > dist/metavoice/version.txt

deploy-server:
python deploy_ml.py
52 changes: 52 additions & 0 deletions services/desktop_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Voice conversion desktop app

Cross-platform native desktop app that allows the user to convert their voice in real-time to a target voice.


## How to run?
* Install dependencies: `npm install`

* Dev mode: `npm start`
* Prod mode:
* Package server: `make build-server`
* Package electron: `npm run package`
* Run by opening `out/MetaVoice-darwin-arm64/MetaVoice.app`

### adding a voice
You should add the .npy file we provide to `%APPDATA%/speakers/`, on windows.

## deploy
### mvml

```sh
make build-server-{platform}

# manually update `config > mlVersion` in package.json

# this will create the zip file and upload it to s3
python deploy_ml.py
```

That's all. An mvml deployment doesn't automatically cause older user instances to update, you'll need to deploy the electron package
with the updated `config > mlVersion` in package.json

### electron
```sh
# IF anything in the frontend changed, including assets/html/css/react
npm run react-package

# manually update `version` in package.json

# populates the out/ dir
npm run electron-package-win

# cleans the destination dir from evidence of usage, and zips the file with the right version.
# To be safe when deploying, you might want to rebuild after usage, or mvml and other files might be included
python deploy_el.py
```

Now you can use the zip file at the location specified in the logs of the last command, and manually upload it as a latest release to https://github.com/metavoicexyz/MetaVoiceCode-deploy/releases .

Don't change the file name. Make sure the release tag is valid semver, e.g. `v1.2.3`.

The update mechanism is dependent on `metavoicexyz/MetaVoiceCode-deploy` being the repo you release to, and this repo being public. The repo itself doesn't need to contain any code.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/desktop_app/assets/avatar-eva.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/desktop_app/assets/avatar-scarlett.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/desktop_app/assets/avatar-yara.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/desktop_app/assets/avatar-zeus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/desktop_app/assets/icon.icns
Binary file not shown.
Binary file added services/desktop_app/assets/icon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions services/desktop_app/deploy_electron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# cleans the build directory from mvml and zips the electron build.
# assumes `npm run react-package && npm run electron-package-build` has been run

import os
import json

from dotenv import load_dotenv
load_dotenv()

import boto3
import shutil

def deploy():
el_version = json.load(open("package.json"))["version"]
# see https://github.com/electron/update.electronjs.org/blob/main/src/asset-platform.js
platform = 'win32-x64' if os.name == 'nt' else 'darwin' # matches electron's process.platform
src_path = f"out/MetaVoice-{platform}" # TODO test works for other platforms
dest_path = f"out/MetaVoice-{el_version}-{platform}"

print(f'cleaning {src_path} ...')
# remove dist folder
if os.path.exists(src_path + "/resources/app/dist"):
print('- removing /resources/app/dist ...')
shutil.rmtree(src_path + "/resources/app/dist")

# remove mvml-*.zip files
for f in os.listdir(src_path + "/resources/app"):
if f.startswith("mvml-") and f.endswith(".zip"):
print('- removing /resources/app/' + f + ' ...')
os.remove(src_path + "/resources/app/" + f)

print(f'zipping to {dest_path}.zip ...')

shutil.make_archive(dest_path, "zip", src_path)

# TODO automatic upload mvml if new version?
# TODO automatic upload to github?

print('done! You can upload it as an appendix to the github release.')

if __name__ == '__main__':
deploy()
38 changes: 38 additions & 0 deletions services/desktop_app/deploy_ml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import hashlib
import json
import os
import shutil

import boto3
from dotenv import load_dotenv

load_dotenv()

ml_version = json.load(open("package.json"))["config"]["mlVersion"]
platform = "win32" if os.name == "nt" else "darwin" # matches electron's process.platform
dest_path = f"mvml/mvml-{platform}-{ml_version}.zip"

print(f"preparing to push to {dest_path} ...")
# add version as version.txt to dist
with open("dist/metavoice/version.txt", "w") as f:
f.write(ml_version)

print("zipping to mvml-local.zip ...")
shutil.make_archive("mvml-local", "zip", "dist")

print("creating sha256 checksum ...")
checksum = hashlib.sha256(open("mvml-local.zip", "rb").read()).hexdigest()
print("checksum:", checksum)

print("initiating s3 ...")
s3c = boto3.client(
"s3",
aws_access_key_id=os.getenv("KEY_AWS_ACCESS"),
aws_secret_access_key=os.getenv("KEY_AWS_SECRET_ACCESS"),
)

print("uploading to s3 ...")
s3c.upload_file("mvml-local.zip", "mv-downloads", dest_path)
s3c.upload_file("mvml-local.zip", "mv-downloads", f"{dest_path}.sha256")

print("done!")
16 changes: 16 additions & 0 deletions services/desktop_app/entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
13 changes: 13 additions & 0 deletions services/desktop_app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>MetaVoice</title>
</head>
<body>
<div id="root"></div>
<script src="./src/index.js"></script>
</body>
</html>
Loading

0 comments on commit 344ab65

Please sign in to comment.