edit pipeline
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import numpy as np
|
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
-
from transformers import
|
7 |
|
8 |
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
device = "cpu"
|
@@ -11,6 +11,8 @@ device = "cpu"
|
|
11 |
# load speech translation checkpoint
|
12 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
13 |
|
|
|
|
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
16 |
model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
@@ -22,13 +24,13 @@ speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze
|
|
22 |
|
23 |
def translate(audio):
|
24 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
25 |
-
|
|
|
26 |
|
27 |
|
28 |
def synthesise(text):
|
29 |
inputs = processor(text=text, return_tensors="pt")
|
30 |
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
31 |
-
# return speech.cpu()
|
32 |
return speech.to(device)
|
33 |
|
34 |
|
|
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
+
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, pipeline
|
7 |
|
8 |
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
device = "cpu"
|
|
|
11 |
# load speech translation checkpoint
|
12 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
13 |
|
14 |
+
translation_pipe = pipeline('translation', model="Helsinki-NLP/opus-mt-en-nl", device=device)
|
15 |
+
|
16 |
# load text-to-speech checkpoint and speaker embeddings
|
17 |
processor = SpeechT5Processor.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
18 |
model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
|
|
24 |
|
25 |
def translate(audio):
|
26 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
27 |
+
dutch_translation = translation_pipe(outputs["text"])[0]['translation_text']
|
28 |
+
return dutch_translation
|
29 |
|
30 |
|
31 |
def synthesise(text):
|
32 |
inputs = processor(text=text, return_tensors="pt")
|
33 |
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
|
|
34 |
return speech.to(device)
|
35 |
|
36 |
|