Commit 608167d7 authored by Carl De Sousa Trias's avatar Carl De Sousa Trias
Browse files

Update requirements.txt, TTS.py

parent 5ea04f0c
Pipeline #54 canceled with stages
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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment