Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,11 @@ from waitress import serve
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
-
#
|
13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
-
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if device == "cuda" else -1)
|
15 |
|
16 |
-
# Function to generate
|
17 |
def generate_audio_prompt(text, filename):
|
18 |
tts = gTTS(text=text, lang="en")
|
19 |
tts.save(os.path.join("static", filename))
|
@@ -54,8 +54,8 @@ def convert_to_wav(input_path, output_path):
|
|
54 |
# Function to check if audio contains actual speech
|
55 |
def is_silent_audio(audio_path):
|
56 |
audio = AudioSegment.from_wav(audio_path)
|
57 |
-
nonsilent_parts = detect_nonsilent(audio, min_silence_len=
|
58 |
-
return len(nonsilent_parts) == 0
|
59 |
|
60 |
@app.route("/")
|
61 |
def index():
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
+
# Use whisper-small for faster processing and better speed
|
13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
+
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if device == "cuda" else -1)
|
15 |
|
16 |
+
# Function to generate audio prompts
|
17 |
def generate_audio_prompt(text, filename):
|
18 |
tts = gTTS(text=text, lang="en")
|
19 |
tts.save(os.path.join("static", filename))
|
|
|
54 |
# Function to check if audio contains actual speech
|
55 |
def is_silent_audio(audio_path):
|
56 |
audio = AudioSegment.from_wav(audio_path)
|
57 |
+
nonsilent_parts = detect_nonsilent(audio, min_silence_len=500, silence_thresh=audio.dBFS-16) # Reduced silence duration
|
58 |
+
return len(nonsilent_parts) == 0 # If no speech detected
|
59 |
|
60 |
@app.route("/")
|
61 |
def index():
|