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
65f779de
Commit
65f779de
authored
6 months ago
by
Andres Marafioti
Browse files
Options
Downloads
Patches
Plain Diff
review from eustache
parent
65bef760
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
LLM/language_model.py
+11
-11
11 additions, 11 deletions
LLM/language_model.py
STT/whisper_stt_handler.py
+14
-14
14 additions, 14 deletions
STT/whisper_stt_handler.py
TTS/melo_handler.py
+21
-23
21 additions, 23 deletions
TTS/melo_handler.py
with
46 additions
and
48 deletions
LLM/language_model.py
+
11
−
11
View file @
65f779de
...
...
@@ -19,12 +19,12 @@ console = Console()
WHISPER_LANGUAGE_TO_LLM_LANGUAGE
=
{
"
<|en|>
"
:
"
english
"
,
"
<|fr|>
"
:
"
french
"
,
"
<|es|>
"
:
"
spanish
"
,
"
<|zh|>
"
:
"
chinese
"
,
"
<|ja|>
"
:
"
japanese
"
,
"
<|ko|>
"
:
"
korean
"
,
"
en
"
:
"
english
"
,
"
fr
"
:
"
french
"
,
"
es
"
:
"
spanish
"
,
"
zh
"
:
"
chinese
"
,
"
ja
"
:
"
japanese
"
,
"
ko
"
:
"
korean
"
,
}
class
LanguageModelHandler
(
BaseHandler
):
...
...
@@ -112,10 +112,10 @@ class LanguageModelHandler(BaseHandler):
def
process
(
self
,
prompt
):
logger
.
debug
(
"
infering language model...
"
)
language_
id
=
None
language_
code
=
None
if
isinstance
(
prompt
,
tuple
):
prompt
,
language_
id
=
prompt
prompt
=
f
"
Please reply to my message in
{
WHISPER_LANGUAGE_TO_LLM_LANGUAGE
[
language_
id
]
}
.
"
+
prompt
prompt
,
language_
code
=
prompt
prompt
=
f
"
Please reply to my message in
{
WHISPER_LANGUAGE_TO_LLM_LANGUAGE
[
language_
code
]
}
.
"
+
prompt
self
.
chat
.
append
({
"
role
"
:
self
.
user_role
,
"
content
"
:
prompt
})
thread
=
Thread
(
...
...
@@ -135,10 +135,10 @@ class LanguageModelHandler(BaseHandler):
printable_text
+=
new_text
sentences
=
sent_tokenize
(
printable_text
)
if
len
(
sentences
)
>
1
:
yield
(
sentences
[
0
],
language_
id
)
yield
(
sentences
[
0
],
language_
code
)
printable_text
=
new_text
self
.
chat
.
append
({
"
role
"
:
"
assistant
"
,
"
content
"
:
generated_text
})
# don't forget last sentence
yield
(
printable_text
,
language_
id
)
yield
(
printable_text
,
language_
code
)
This diff is collapsed.
Click to expand it.
STT/whisper_stt_handler.py
+
14
−
14
View file @
65f779de
...
...
@@ -13,12 +13,12 @@ logger = logging.getLogger(__name__)
console
=
Console
()
SUPPORTED_LANGUAGES
=
[
"
<|en|>
"
,
"
<|fr|>
"
,
"
<|es|>
"
,
"
<|zh|>
"
,
"
<|ja|>
"
,
"
<|ko|>
"
,
"
en
"
,
"
fr
"
,
"
es
"
,
"
zh
"
,
"
ja
"
,
"
ko
"
,
]
...
...
@@ -117,24 +117,24 @@ class WhisperSTTHandler(BaseHandler):
input_features
=
self
.
prepare_model_inputs
(
spoken_prompt
)
pred_ids
=
self
.
model
.
generate
(
input_features
,
**
self
.
gen_kwargs
)
language_
id
=
self
.
processor
.
tokenizer
.
decode
(
pred_ids
[
0
,
1
])
language_
code
=
self
.
processor
.
tokenizer
.
decode
(
pred_ids
[
0
,
1
])
[
2
:
-
2
]
# remove "<|" and "|>"
if
language_
id
not
in
SUPPORTED_LANGUAGES
:
# reprocess with the last language
logger
.
warning
(
"
Whisper detected unsupported language:
"
,
language_
id
)
if
language_
code
not
in
SUPPORTED_LANGUAGES
:
# reprocess with the last language
logger
.
warning
(
"
Whisper detected unsupported language:
"
,
language_
code
)
gen_kwargs
=
copy
(
self
.
gen_kwargs
)
gen_kwargs
[
'
language
'
]
=
self
.
last_language
language_
id
=
self
.
last_language
language_
code
=
self
.
last_language
pred_ids
=
self
.
model
.
generate
(
input_features
,
**
gen_kwargs
)
else
:
self
.
last_language
=
language_
id
self
.
last_language
=
language_
code
pred_text
=
self
.
processor
.
batch_decode
(
pred_ids
,
skip_special_tokens
=
True
,
decode_with_timestamps
=
False
)[
0
]
language_
id
=
self
.
processor
.
tokenizer
.
decode
(
pred_ids
[
0
,
1
])
language_
code
=
self
.
processor
.
tokenizer
.
decode
(
pred_ids
[
0
,
1
])
[
2
:
-
2
]
# remove "<|" and "|>"
logger
.
debug
(
"
finished whisper inference
"
)
console
.
print
(
f
"
[yellow]USER:
{
pred_text
}
"
)
logger
.
debug
(
f
"
Language
ID
Whisper:
{
language_
id
}
"
)
logger
.
debug
(
f
"
Language
Code
Whisper:
{
language_
code
}
"
)
yield
(
pred_text
,
language_
id
)
yield
(
pred_text
,
language_
code
)
This diff is collapsed.
Click to expand it.
TTS/melo_handler.py
+
21
−
23
View file @
65f779de
...
...
@@ -11,21 +11,21 @@ logger = logging.getLogger(__name__)
console
=
Console
()
WHISPER_LANGUAGE_TO_MELO_LANGUAGE
=
{
"
<|en|>
"
:
"
EN_NEWEST
"
,
"
<|fr|>
"
:
"
FR
"
,
"
<|es|>
"
:
"
ES
"
,
"
<|zh|>
"
:
"
ZH
"
,
"
<|ja|>
"
:
"
JP
"
,
"
<|ko|>
"
:
"
KR
"
,
"
en
"
:
"
EN_NEWEST
"
,
"
fr
"
:
"
FR
"
,
"
es
"
:
"
ES
"
,
"
zh
"
:
"
ZH
"
,
"
ja
"
:
"
JP
"
,
"
ko
"
:
"
KR
"
,
}
WHISPER_LANGUAGE_TO_MELO_SPEAKER
=
{
"
<|en|>
"
:
"
EN-Newest
"
,
"
<|fr|>
"
:
"
FR
"
,
"
<|es|>
"
:
"
ES
"
,
"
<|zh|>
"
:
"
ZH
"
,
"
<|ja|>
"
:
"
JP
"
,
"
<|ko|>
"
:
"
KR
"
,
"
en
"
:
"
EN-Newest
"
,
"
fr
"
:
"
FR
"
,
"
es
"
:
"
ES
"
,
"
zh
"
:
"
ZH
"
,
"
ja
"
:
"
JP
"
,
"
ko
"
:
"
KR
"
,
}
...
...
@@ -41,14 +41,12 @@ class MeloTTSHandler(BaseHandler):
):
self
.
should_listen
=
should_listen
self
.
device
=
device
self
.
language
=
(
"
<|
"
+
language
+
"
|>
"
)
# 'Tokenize' the language code to do less operations
self
.
language
=
language
self
.
model
=
TTS
(
language
=
WHISPER_LANGUAGE_TO_MELO_LANGUAGE
[
self
.
language
],
device
=
device
)
self
.
speaker_id
=
self
.
model
.
hps
.
data
.
spk2id
[
WHISPER_LANGUAGE_TO_MELO_SPEAKER
[
"
<|
"
+
speaker_to_id
+
"
|>
"
]
WHISPER_LANGUAGE_TO_MELO_SPEAKER
[
speaker_to_id
]
]
self
.
blocksize
=
blocksize
self
.
warmup
()
...
...
@@ -58,26 +56,26 @@ class MeloTTSHandler(BaseHandler):
_
=
self
.
model
.
tts_to_file
(
"
text
"
,
self
.
speaker_id
,
quiet
=
True
)
def
process
(
self
,
llm_sentence
):
language_
id
=
None
language_
code
=
None
if
isinstance
(
llm_sentence
,
tuple
):
llm_sentence
,
language_
id
=
llm_sentence
llm_sentence
,
language_
code
=
llm_sentence
console
.
print
(
f
"
[green]ASSISTANT:
{
llm_sentence
}
"
)
if
language_
id
is
not
None
and
self
.
language
!=
language_
id
:
if
language_
code
is
not
None
and
self
.
language
!=
language_
code
:
try
:
self
.
model
=
TTS
(
language
=
WHISPER_LANGUAGE_TO_MELO_LANGUAGE
[
language_
id
],
language
=
WHISPER_LANGUAGE_TO_MELO_LANGUAGE
[
language_
code
],
device
=
self
.
device
,
)
self
.
speaker_id
=
self
.
model
.
hps
.
data
.
spk2id
[
WHISPER_LANGUAGE_TO_MELO_SPEAKER
[
language_
id
]
WHISPER_LANGUAGE_TO_MELO_SPEAKER
[
language_
code
]
]
self
.
language
=
language_
id
self
.
language
=
language_
code
except
KeyError
:
console
.
print
(
f
"
[red]Language
{
language_
id
}
not supported by Melo. Using
{
self
.
language
}
instead.
"
f
"
[red]Language
{
language_
code
}
not supported by Melo. Using
{
self
.
language
}
instead.
"
)
if
self
.
device
==
"
mps
"
:
...
...
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