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

fix issue in upload and offlind-record pages of python streaming server #284

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 8 additions & 5 deletions python-api-examples/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
("/js/bootstrap.min.js", "application/javascript"),
("/js/bootstrap.min.js.map", "application/javascript"),
("/js/jquery-3.6.0.min.js", "application/javascript"),
("/js/offline_record.js", "application/javascript"),
("/js/offline_record.js", "application/javascript"),
("/js/offline_record_streaming.js", "application/javascript"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline and non-streaming are synonymous.

Please either use offline_record.js or use non_streaming_record.js.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think offline record just means we record the voice into one buffer, like a file,
then we still have streaming and non-streaming mode to transcribe the buffer,
streaming mode is to send the buffer bytes in stream and receive the result at the same time,
while non-streaming mode is to send the whole buffer firstly
and then receive the whole result text in one response,
so we should still need two different js files for offline record.

("/js/offline_record_non_streaming.js", "application/javascript"),
("/js/popper.min.js", "application/javascript"),
("/js/popper.min.js.map", "application/javascript"),
("/js/streaming_record.js", "application/javascript"),
("/js/upload.js", "application/javascript"),
("/js/upload_streaming.js", "application/javascript"),
("/js/upload_non_streaming.js", "application/javascript"),
("/k2-logo.png", "image/png"),
("/nav-partial.html", "text/html"),
("/offline_record.html", "text/html"),
("/offline_record_streaming.html", "text/html"),
("/offline_record_non_streaming.html", "text/html"),
("/streaming_record.html", "text/html"),
("/upload.html", "text/html"),
("/upload_streaming.html", "text/html"),
("/upload_non_streaming.html", "text/html"),
)

_404_page = r"""
Expand Down
4 changes: 4 additions & 0 deletions python-api-examples/non_streaming_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ async def process_request(
# This is a normal HTTP request
if path == "/":
path = "/index.html"
if path == "/upload.html":
path = "/upload_non_streaming.html"
if path == "/offline_record.html":
path = "/offline_record_non_streaming.html"
if path[-1] == "?":
path = path[:-1]

Expand Down
20 changes: 5 additions & 15 deletions python-api-examples/streaming_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,21 +498,11 @@ async def process_request(
# This is a normal HTTP request
if path == "/":
path = "/index.html"

if path in ("/upload.html", "/offline_record.html"):
response = r"""
<!doctype html><html><head>
<title>Speech recognition with next-gen Kaldi</title><body>
<h2>Only /streaming_record.html is available for the streaming server.<h2>
<br/>
<br/>
Go back to <a href="/streaming_record.html">/streaming_record.html</a>
</body></head></html>
"""
found = True
mime_type = "text/html"
else:
found, response, mime_type = self.http_server.process_request(path)
if path == "/upload.html":
path = "/upload_streaming.html"
if path == "/offline_record.html":
path = "/offline_record_streaming.html"
found, response, mime_type = self.http_server.process_request(path)

if isinstance(response, str):
response = response.encode("utf-8")
Expand Down
Loading