Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asr-benchmarks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcin Wątroba
asr-benchmarks
Merge requests
!5
Add base ASR serice
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Add base ASR serice
feature/add_base_asr_service
into
main
Overview
1
Commits
1
Pipelines
0
Changes
5
Merged
Add base ASR serice
Marcin Wątroba
requested to merge
feature/add_base_asr_service
into
main
Aug 10, 2021
Overview
1
Commits
1
Pipelines
0
Changes
5
Created by: markowanga
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
7f904960
1 commit,
Nov 18, 2022
5 files
+
169
−
3
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
sziszapangma/integration/base_asr_service/asr_processor.py
0 → 100644
+
45
−
0
View file @ 7f904960
Edit in single-file editor
Open in Web IDE
import
os
import
uuid
from
abc
import
ABC
,
abstractmethod
from
pathlib
import
Path
from
asr_result
import
AsrResult
from
flask
import
Flask
,
Response
,
jsonify
,
request
_TEMP_DIRECTORY
=
"
asr_processing
"
class
AsrProcessor
(
ABC
):
def
__init__
(
self
):
self
.
read_user_credentials
=
self
.
read_user_credentials
()
self
.
_cached_users_credentials
=
None
@abstractmethod
def
process_asr
(
self
,
audio_file_path
:
str
)
->
AsrResult
:
"""
Method to call for ASR results.
"""
def
process_request
(
self
)
->
Response
:
file_tag
=
str
(
uuid
.
uuid4
())
f
=
request
.
files
[
"
file
"
]
if
f
is
not
None
and
f
.
filename
is
not
None
:
file_extension
=
f
.
filename
.
split
(
"
.
"
)[
-
1
]
file_name
=
f
"
{
file_tag
}
.
{
file_extension
}
"
file_path
=
f
"
{
_TEMP_DIRECTORY
}
/
{
file_name
}
"
f
.
save
(
file_path
)
try
:
transcription
=
self
.
process_asr
(
file_path
)
os
.
remove
(
file_path
)
result_object
=
jsonify
(
{
"
transcription
"
:
transcription
.
words
,
"
full_text
"
:
transcription
.
full_text
}
)
except
:
result_object
=
jsonify
({
"
error
"
:
"
Error on asr processing
"
})
else
:
result_object
=
jsonify
({
"
error
"
:
"
Error on asr processing
"
})
return
result_object
def
start_processor
(
self
):
app
=
Flask
(
__name__
)
Path
(
_TEMP_DIRECTORY
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
app
.
route
(
"
/process_asr
"
,
methods
=
[
"
POST
"
])(
self
.
process_request
)
app
.
run
(
debug
=
True
,
host
=
"
0.0.0.0
"
)
Loading