lokesh341 commited on
Commit
1547e12
·
verified ·
1 Parent(s): 37849e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -9,11 +9,11 @@ from waitress import serve
9
 
10
  app = Flask(__name__)
11
 
12
- # Load Whisper ASR Model for Better Speed & Accuracy
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) # Small model for faster inference
15
 
16
- # Function to generate voice prompts
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=300, silence_thresh=audio.dBFS-16) # Reduced silence duration
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():