microsoft / SpeechT5

Unified-Modal Speech-Text Pre-Training for Spoken Language Processing
MIT License
1.21k stars 114 forks source link

Are there any performance optimization for inference available for this model or faster inference versions or streaming I only find this example? #93

Open lukaLLM opened 4 weeks ago

lukaLLM commented 4 weeks ago
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
from datasets import load_dataset
import torch
import soundfile as sf
from datasets import load_dataset
import time

processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

inputs = processor(text="My dog is better ", return_tensors="pt")

# 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)

# Measure time for speech generation
start_time = time.time()
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
end_time = time.time()

generation_time = end_time - start_time
print(f"Speech generation took {generation_time:.2f} seconds")

sf.write("speech.wav", speech.numpy(), samplerate=16000)