File size: 1,334 Bytes
29aa39e 3bba8cf 29aa39e 4fe97cd 29aa39e 4fe97cd 29aa39e 4fe97cd 29aa39e 4fe97cd 3bba8cf 4fe97cd 29aa39e 4fe97cd | 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 | import streamlit as st
import yt_dlp
import ffmpeg
import os
# Membuat fungsi untuk mengunduh audio dari YouTube
def download_audio(url):
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}],
'outtmpl': 'audio.mp3'
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
st.success('Audio berhasil diunduh!')
# Membuat fungsi untuk menerjemahkan teks menggunakan model Whisper
def translate_text(audio_file):
os.system(f'whisper "{audio_file}" --model small.en --language en --best_of 20 --word_timestamps True --output_format srt --task transcribe')
with open('audio.srt', 'r') as f:
text = f.read()
st.write(text)
# Membuat tampilan UI menggunakan Streamlit
st.title('Aplikasi Penerjemah Audio YouTube')
url = st.text_input('Masukkan URL video YouTube')
if st.button('Unduh Audio'):
download_audio(url)
if st.button('Terjemahkan Teks'):
translate_text('audio.mp3')
st.success('Teks berhasil diterjemahkan!')
with open('audio.srt', 'r') as f:
srt_text = f.read()
with open('translated_text.srt', 'w') as f:
f.write(srt_text)
st.download_button('Unduh Hasil Terjemahan', data=srt_text, file_name='translated_text.srt')
|