Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
MPAI-MMC
Implementation of MMC-TTS
Commits
608167d7
Commit
608167d7
authored
Sep 27, 2024
by
Carl De Sousa Trias
Browse files
Update requirements.txt, TTS.py
parent
5ea04f0c
Pipeline
#54
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
TTS.py
0 → 100644
View file @
608167d7
import
torch
from
transformers
import
pipeline
import
soundfile
as
sf
from
datasets
import
load_dataset
device
=
torch
.
device
(
"cuda"
if
torch
.
cuda
.
is_available
()
else
"cpu"
)
class
TextToSpeech
():
AnswerText
=
None
AnswerAudio
=
None
def
funcTextToSpeech
(
self
,
input
):
synthesiser
=
pipeline
(
"text-to-speech"
,
"microsoft/speecht5_tts"
,
device
=
device
)
embeddings_dataset
=
load_dataset
(
"Matthijs/cmu-arctic-xvectors"
,
split
=
"validation"
)
speaker_embedding
=
torch
.
tensor
(
embeddings_dataset
[
7306
][
"xvector"
]).
unsqueeze
(
0
)
# You can replace this embedding with your own as well.
speech
=
synthesiser
(
input
,
forward_params
=
{
"speaker_embeddings"
:
speaker_embedding
})
path_output
=
"AudioAnswer.wav"
sf
.
write
(
path_output
,
speech
[
"audio"
],
samplerate
=
speech
[
"sampling_rate"
])
return
path_output
def
run
(
self
):
self
.
AnswerAudio
=
self
.
funcTextToSpeech
(
self
.
AnswerText
)
if
__name__
==
'__main__'
:
module
=
TextToSpeech
()
module
.
AnswerText
=
"Text as a string"
module
.
run
()
requirements.txt
0 → 100644
View file @
608167d7
torch
transformers
datasets
soundfile
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment