-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4af0867
commit fd77bef
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .utils.storages import tmp_file # noqa: F401 | ||
from .blip_image_captioning_large import blip_image_captioning_large # noqa: F401 | ||
from .yolos_tiny import yolos_tiny # noqa: F401 | ||
from .yolos_tiny import yolos_tiny # noqa: F401 | ||
from .speecht5_tts import speecht5_tts # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan | ||
from datasets import load_dataset | ||
import torch | ||
import soundfile as sf | ||
import uuid | ||
|
||
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts") | ||
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts") | ||
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan") | ||
|
||
def speecht5_tts(text: str) -> str: | ||
inputs = processor(text=text, return_tensors="pt") | ||
outputs = f"{uuid.uuid4()}.mp3" | ||
|
||
# load xvector containing speaker's voice characteristics from a dataset | ||
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation") | ||
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0) | ||
|
||
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder) | ||
|
||
sf.write(f"outputs/{outputs}", speech.numpy(), samplerate=16000) | ||
|
||
return f"http://localhost:8000/audio/{outputs}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters