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

Handle supported languages with no example audio file #4

Merged
merged 2 commits into from
May 5, 2023
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
4 changes: 3 additions & 1 deletion ovos_stt_http_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def main():
default="en-us")
parser.add_argument("--gradio", help="Enable Gradio Web UI",
action="store_true")
parser.add_argument("--cache", help="Cache models for Gradio demo",
action="store_true")
parser.add_argument("--title", help="Title for webUI",
default="STT")
parser.add_argument("--description", help="Text description to print in UI",
Expand All @@ -40,7 +42,7 @@ def main():
LOG.info("Server Started")
if args.gradio:
bind_gradio_service(server, engine, args.title, args.description,
args.info, args.badge, args.lang)
args.info, args.badge, args.lang, args.cache)
LOG.info("Gradio Started")
uvicorn.run(server, host=args.host, port=args.port)

Expand Down
7 changes: 4 additions & 3 deletions ovos_stt_http_server/gradio_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import gradio as gr

from os.path import join, dirname, basename, splitext
from os.path import join, dirname, basename, splitext, isfile
from ovos_utils.log import LOG
from ovos_stt_http_server import ModelContainer, bytes2audiodata

Expand All @@ -16,7 +16,7 @@ def transcribe(audio_file, language: str):

def bind_gradio_service(app, stt_engine: ModelContainer,
title, description, info, badge,
default_lang="en"):
default_lang="en", cache=True):
global STT
STT = stt_engine
languages = list(stt_engine.plugin().available_languages or [default_lang])
Expand All @@ -32,6 +32,7 @@ def bind_gradio_service(app, stt_engine: ModelContainer,

examples = [join(dirname(__file__), 'audio', f'{lang.split("-")[0]}.mp3')
for lang in languages]
examples = [example for example in examples if isfile(example)]
iface = gr.Interface(
fn=transcribe,
inputs=[
Expand All @@ -46,7 +47,7 @@ def bind_gradio_service(app, stt_engine: ModelContainer,
"textbox"
],
examples=[[e, basename(splitext(e)[0])] for e in examples],
cache_examples=True, # Takes some time at init, but speeds up runtime
cache_examples=cache, # Takes some time at init, but speeds up runtime
live=True,
title=title,
description=description,
Expand Down
17 changes: 12 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ ovos-stt-server --help
usage: ovos-stt-server [-h] [--engine ENGINE] [--port PORT] [--host HOST]

options:
-h, --help show this help message and exit
--engine ENGINE stt plugin to be used
--port PORT port number
--host HOST host
-h, --help show this help message and exit
--engine ENGINE stt plugin to be used
--port PORT port number
--host HOST host
--lang LANG default language
--gradio flag to enable Gradio web UI
--cache flag to pre-cache examples in Gradio web UI
--title TITLE title for Gradio UI
--description DESCRIPTION Description for Gradio UI
--info INFO Text to display in Gradio UI
--badge BADGE URL of badge to show in Gradio UI
```

> Note: `ffmpeg` is required for Gradio
## Companion plugin

Use with OpenVoiceOS [companion plugin](https://github.com/OpenVoiceOS/ovos-stt-server-plugin)
Expand Down