Skip to content

Commit

Permalink
Add local server
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hansen committed Feb 8, 2020
1 parent 5cc330a commit ed06cee
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 12 deletions.
44 changes: 44 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Github-like download interface"""
import typing
from pathlib import Path
from uuid import uuid4

from quart import Quart, send_from_directory, Response

app = Quart("rhasspy")
app.secret_key = str(uuid4())

# -----------------------------------------------------------------------------

profile_dirs: typing.Dict[str, Path] = {}
for check_dir in Path(".").glob("*"):
if not check_dir.is_dir():
continue

for profile_dir in check_dir.glob("*"):
if not profile_dir.is_dir():
continue

profile_yml = profile_dir / "profile.yml"
if profile_yml.is_file():
profile_dirs[profile_dir.name] = profile_dir

# -----------------------------------------------------------------------------


@app.route("/<path:path>")
async def download_raw(path: str) -> Response:
components = path.split("/")
profile = components[0]
artifact = "/".join(components[3:])

profile_dir = profile_dirs.get(profile)
assert profile_dir, f"Missing directory for {profile}"

return await send_from_directory(profile_dir, artifact)


# -----------------------------------------------------------------------------

if __name__ == "__main__":
app.run()
18 changes: 16 additions & 2 deletions bin/check_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():
]

for p in common_files:
if not p.exists():
if not path_exists(p):
print(profile_name, "missing", p.name)

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -63,11 +63,25 @@ def main():
)

for p in kaldi_files:
if not p.exists():
if not path_exists(p):
print(profile_name, "missing", p.name)


# -----------------------------------------------------------------------------

def path_exists(path):
if not path.exists():
# Try .gz
gzip_path = path.parent / f"{path.name}.gz"
if not gzip_path.exists():
# Try .gz-part-00
part0_path = path.parent / f"{path.name}.gz.part-00"

return part0_path.exists()

return True

# -----------------------------------------------------------------------------

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion bin/guess_espeak_phonemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
)
parser.add_argument("frequent_words", help="Path to text file with frequent words")
parser.add_argument("dictionary", help="Path to pronunciation dictionary")
parser.add_argument("--voice", help="espeak voice")
parser.add_argument("--voice", required=True, help="espeak voice")
parser.add_argument(
"--exclude_chars", nargs="*", default=["'"], help="Phoneme characters to exclude"
)
Expand Down
46 changes: 46 additions & 0 deletions bin/make_download_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
import argparse
import json
import os
import sys
from pathlib import Path


def main():
parser = argparse.ArgumentParser(prog="make_download_json.py")
# parser.add_argument("url_base")
parser.add_argument("profile_dir")
parser.add_argument("files", nargs="+")
args = parser.parse_args()

# url_base = args.url_base
profile_dir = Path(args.profile_dir).absolute()
files = {}
for file_name in args.files:
file_path = Path(file_name).absolute()
file_key = str(file_path.relative_to(profile_dir))
files[file_key] = file_path

json.dump(
{
"conditions": {
file_key: f"{profile_dir.name}/{file_key}" for file_key in files
},
"files": {
f"{profile_dir.name}/{file_key}": {
"url": f"{profile_dir.name}/raw/master/{file_key}",
"bytes_expected": os.path.getsize(file_path),
"unzip": file_path.suffix == ".gz",
}
for file_key, file_path in files.items()
},
},
sys.stdout,
indent=4,
)


# -----------------------------------------------------------------------------

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion english/en-us_julius-github
2 changes: 1 addition & 1 deletion german/de_kaldi-zamia
2 changes: 1 addition & 1 deletion polish/pl_julius-github
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ requests
pyyaml
pydash
conllu
quart==0.6.15
2 changes: 1 addition & 1 deletion vietnamese/vi_kaldi-montreal

0 comments on commit ed06cee

Please sign in to comment.