Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,10 @@
|
|
4 |
# Description: This script record the audio, transform it to text, detect the language of the file and save it to a txt file.
|
5 |
# import required modules
|
6 |
import os
|
7 |
-
import whisper
|
8 |
-
from langdetect import detect
|
9 |
-
import torch
|
10 |
import streamlit as st
|
11 |
from audio_recorder_streamlit import audio_recorder
|
12 |
-
import
|
|
|
13 |
|
14 |
# Function to open a file
|
15 |
def startfile(fn):
|
@@ -24,22 +22,19 @@ def create_and_open_txt(text, filename):
|
|
24 |
|
25 |
# Ask user to record audio
|
26 |
st.title("Audio to Text Transcription..")
|
27 |
-
|
28 |
-
|
29 |
-
# Download the audio stream
|
30 |
|
31 |
# Load the base model and transcribe the audio
|
32 |
model = whisper.load_model("base")
|
33 |
-
result = model.transcribe(
|
34 |
transcribed_text = result["text"]
|
35 |
print(transcribed_text)
|
36 |
st.write("Transcription:")
|
37 |
st.write(transcribed_text)
|
38 |
-
|
39 |
|
40 |
# Detect the language
|
41 |
language = detect(transcribed_text)
|
42 |
st.write(f"Detected language: {language}")
|
43 |
|
44 |
# Create and open a txt file with the text
|
45 |
-
create_and_open_txt(transcribed_text, f"output_{language}.txt")
|
|
|
4 |
# Description: This script record the audio, transform it to text, detect the language of the file and save it to a txt file.
|
5 |
# import required modules
|
6 |
import os
|
|
|
|
|
|
|
7 |
import streamlit as st
|
8 |
from audio_recorder_streamlit import audio_recorder
|
9 |
+
import whisper
|
10 |
+
from langdetect import detect
|
11 |
|
12 |
# Function to open a file
|
13 |
def startfile(fn):
|
|
|
22 |
|
23 |
# Ask user to record audio
|
24 |
st.title("Audio to Text Transcription..")
|
25 |
+
audio_bytes = audio_recorder(pause_threshold=3.0, sample_rate=16_000)
|
|
|
|
|
26 |
|
27 |
# Load the base model and transcribe the audio
|
28 |
model = whisper.load_model("base")
|
29 |
+
result = model.transcribe(audio_bytes)
|
30 |
transcribed_text = result["text"]
|
31 |
print(transcribed_text)
|
32 |
st.write("Transcription:")
|
33 |
st.write(transcribed_text)
|
|
|
34 |
|
35 |
# Detect the language
|
36 |
language = detect(transcribed_text)
|
37 |
st.write(f"Detected language: {language}")
|
38 |
|
39 |
# Create and open a txt file with the text
|
40 |
+
create_and_open_txt(transcribed_text, f"output_{language}.txt")
|