Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Speech To Speech
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
huggingface
Speech To Speech
Commits
8ca9df23
Commit
8ca9df23
authored
7 months ago
by
wuhongsheng
Browse files
Options
Downloads
Patches
Plain Diff
feat:add paraformer_zh asr
parent
d3d25c45
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
STT/paraformer_handler.py
+61
-0
61 additions, 0 deletions
STT/paraformer_handler.py
s2s_pipeline.py
+8
-0
8 additions, 0 deletions
s2s_pipeline.py
with
69 additions
and
0 deletions
STT/paraformer_handler.py
0 → 100644
+
61
−
0
View file @
8ca9df23
import
logging
from
time
import
perf_counter
from
tensorstore
import
dtype
from
baseHandler
import
BaseHandler
from
funasr
import
AutoModel
import
numpy
as
np
from
rich.console
import
Console
import
torch
logging
.
basicConfig
(
format
=
"
%(asctime)s - %(name)s - %(levelname)s - %(message)s
"
,
)
logger
=
logging
.
getLogger
(
__name__
)
console
=
Console
()
class
ParaformerSTTHandler
(
BaseHandler
):
"""
Handles the Speech To Text generation using a Whisper model.
"""
def
setup
(
self
,
model_name
=
"
paraformer-zh
"
,
device
=
"
cuda
"
,
torch_dtype
=
"
float32
"
,
compile_mode
=
None
,
gen_kwargs
=
{},
):
print
(
model_name
)
if
len
(
model_name
.
split
(
"
/
"
))
>
1
:
model_name
=
model_name
.
split
(
"
/
"
)[
-
1
]
self
.
device
=
device
self
.
model
=
AutoModel
(
model
=
model_name
)
self
.
warmup
()
def
warmup
(
self
):
logger
.
info
(
f
"
Warming up
{
self
.
__class__
.
__name__
}
"
)
# 2 warmup steps for no compile or compile mode with CUDA graphs capture
n_steps
=
1
dummy_input
=
np
.
array
([
0
]
*
512
,
dtype
=
np
.
float32
)
for
_
in
range
(
n_steps
):
_
=
self
.
model
.
generate
(
dummy_input
)[
0
][
"
text
"
].
strip
().
replace
(
"
"
,
""
)
def
process
(
self
,
spoken_prompt
):
logger
.
debug
(
"
infering paraformer...
"
)
global
pipeline_start
pipeline_start
=
perf_counter
()
pred_text
=
self
.
model
.
generate
(
spoken_prompt
)[
0
][
"
text
"
].
strip
().
replace
(
"
"
,
""
)
torch
.
mps
.
empty_cache
()
logger
.
debug
(
"
finished paraformer inference
"
)
console
.
print
(
f
"
[yellow]USER:
{
pred_text
}
"
)
yield
pred_text
This diff is collapsed.
Click to expand it.
s2s_pipeline.py
+
8
−
0
View file @
8ca9df23
...
...
@@ -243,6 +243,14 @@ def main():
queue_out
=
text_prompt_queue
,
setup_kwargs
=
vars
(
whisper_stt_handler_kwargs
),
)
elif
module_kwargs
.
stt
==
"
paraformer
"
:
from
STT.paraformer_handler
import
ParaformerSTTHandler
stt
=
ParaformerSTTHandler
(
stop_event
,
queue_in
=
spoken_prompt_queue
,
queue_out
=
text_prompt_queue
,
# setup_kwargs=vars(whisper_stt_handler_kwargs),
)
else
:
raise
ValueError
(
"
The STT should be either whisper or whisper-mlx
"
)
if
module_kwargs
.
llm
==
"
transformers
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment