Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
-
import soundfile as sf
|
4 |
import torch
|
5 |
-
from transformers import
|
6 |
from datasets import load_dataset
|
|
|
7 |
|
8 |
# Initialize translation models
|
9 |
translator_urdu = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
|
@@ -34,9 +34,12 @@ def synthesize_speech(text, target_lang):
|
|
34 |
speaker_embedding = torch.tensor(xvectors[0]["xvector"]).unsqueeze(0)
|
35 |
speech = tts_model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
|
41 |
# Streamlit UI
|
42 |
st.title("Language Translator")
|
@@ -63,4 +66,4 @@ if st.button("Translate"):
|
|
63 |
if tts_error:
|
64 |
st.error(tts_error)
|
65 |
else:
|
66 |
-
st.audio(audio_file)
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
|
|
3 |
import torch
|
4 |
+
from transformers import TextToSpeechPipeline
|
5 |
from datasets import load_dataset
|
6 |
+
import io
|
7 |
|
8 |
# Initialize translation models
|
9 |
translator_urdu = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
|
|
|
34 |
speaker_embedding = torch.tensor(xvectors[0]["xvector"]).unsqueeze(0)
|
35 |
speech = tts_model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
|
36 |
|
37 |
+
# Convert the speech to an in-memory WAV file using io.BytesIO
|
38 |
+
audio_io = io.BytesIO()
|
39 |
+
audio_io.write(speech.numpy().tobytes())
|
40 |
+
audio_io.seek(0)
|
41 |
+
|
42 |
+
return audio_io, None
|
43 |
|
44 |
# Streamlit UI
|
45 |
st.title("Language Translator")
|
|
|
66 |
if tts_error:
|
67 |
st.error(tts_error)
|
68 |
else:
|
69 |
+
st.audio(audio_file, format='audio/wav')
|