Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,18 @@ def video_to_audio(video_file):
|
|
| 18 |
audio.write_audiofile(temp_audio_path)
|
| 19 |
return temp_audio_path
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Function to transcribe audio to text
|
| 22 |
def transcribe_audio(audio_file):
|
| 23 |
# Initialize recognizer
|
|
@@ -55,12 +67,16 @@ if uploaded_video is not None:
|
|
| 55 |
st.write("Converting video to audio...")
|
| 56 |
audio_file = video_to_audio(tmp_video_path)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Provide the audio file to the user for download
|
| 59 |
-
st.audio(
|
| 60 |
|
| 61 |
# Transcribe audio to text
|
| 62 |
st.write("Transcribing audio to text...")
|
| 63 |
-
transcription = transcribe_audio(
|
| 64 |
|
| 65 |
# Show the transcription
|
| 66 |
st.text_area("Transcription", transcription, height=300)
|
|
@@ -68,3 +84,4 @@ if uploaded_video is not None:
|
|
| 68 |
# Cleanup temporary files
|
| 69 |
os.remove(tmp_video_path)
|
| 70 |
os.remove(audio_file)
|
|
|
|
|
|
| 18 |
audio.write_audiofile(temp_audio_path)
|
| 19 |
return temp_audio_path
|
| 20 |
|
| 21 |
+
# Function to convert MP3 audio to WAV
|
| 22 |
+
def convert_mp3_to_wav(mp3_file):
|
| 23 |
+
# Load the MP3 file using pydub
|
| 24 |
+
audio = AudioSegment.from_mp3(mp3_file)
|
| 25 |
+
|
| 26 |
+
# Create a temporary WAV file
|
| 27 |
+
temp_wav_path = tempfile.mktemp(suffix=".wav")
|
| 28 |
+
|
| 29 |
+
# Export the audio to the temporary WAV file
|
| 30 |
+
audio.export(temp_wav_path, format="wav")
|
| 31 |
+
return temp_wav_path
|
| 32 |
+
|
| 33 |
# Function to transcribe audio to text
|
| 34 |
def transcribe_audio(audio_file):
|
| 35 |
# Initialize recognizer
|
|
|
|
| 67 |
st.write("Converting video to audio...")
|
| 68 |
audio_file = video_to_audio(tmp_video_path)
|
| 69 |
|
| 70 |
+
# Convert the extracted MP3 audio to WAV
|
| 71 |
+
st.write("Converting audio to WAV...")
|
| 72 |
+
wav_audio_file = convert_mp3_to_wav(audio_file)
|
| 73 |
+
|
| 74 |
# Provide the audio file to the user for download
|
| 75 |
+
st.audio(wav_audio_file, format='audio/wav')
|
| 76 |
|
| 77 |
# Transcribe audio to text
|
| 78 |
st.write("Transcribing audio to text...")
|
| 79 |
+
transcription = transcribe_audio(wav_audio_file)
|
| 80 |
|
| 81 |
# Show the transcription
|
| 82 |
st.text_area("Transcription", transcription, height=300)
|
|
|
|
| 84 |
# Cleanup temporary files
|
| 85 |
os.remove(tmp_video_path)
|
| 86 |
os.remove(audio_file)
|
| 87 |
+
os.remove(wav_audio_file)
|