-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (33 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from TTS.api import TTS
import whisper
from tempfile import NamedTemporaryFile
import streamlit as st
# from faster_whisper import WhisperModel
from googletrans import Translator
import nltk
audio = st.file_uploader("Upload an audio file", type=["wav"])
if audio is not None:
with NamedTemporaryFile(delete=False, suffix="wav") as temp_audio:
temp_audio.write(audio.read())
temp_audio_path = temp_audio.name
st.write(f"Temporary audio file saved at: {temp_audio_path}")
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
model = whisper.load_model("base")
result = model.transcribe(temp_audio_path)
print(result["text"])
fin=[]
sentences = result["text"]
translator = Translator()
# for sentence in sentences:
# conv=translator.translate(result, dest='fr')
# fin+=conv.pronunciation
conv=translator.translate(sentences, dest='fr')
print(conv)
st.write(conv.text)
tts.tts_to_file(
text=conv.text,
file_path="output.wav",
speaker_wav=temp_audio_path,
language="fr"
)
st.audio("output.wav", format="audio/wav")