Yehor commited on
Commit
05c3995
·
1 Parent(s): 9dcd0e0

Fix issues

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -6,6 +6,7 @@ from zipfile import ZipFile, ZIP_DEFLATED
6
  from shutil import rmtree
7
  from importlib.metadata import version
8
 
 
9
  import torch
10
  import sentry_sdk
11
  import gradio as gr
@@ -76,6 +77,18 @@ def inference_func(wav_file, min_sec, max_sec):
76
  n_files = 0
77
  duration_secs = 0
78
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  # Rename the file
80
  old_wav_file = wav_file
81
  wav_file = "input.wav"
 
6
  from shutil import rmtree
7
  from importlib.metadata import version
8
 
9
+ import sphn
10
  import torch
11
  import sentry_sdk
12
  import gradio as gr
 
77
  n_files = 0
78
  duration_secs = 0
79
 
80
+ # Validate the file
81
+ try:
82
+ data, sr = sphn.read(wav_file)
83
+ duration = len(data[0]) / sr
84
+ if duration < 0.1:
85
+ raise gr.Error("The duration is too low")
86
+ n_channels = len(data)
87
+ if n_channels > 1:
88
+ raise gr.Error(f"Your file must be in the mono format. The file has {n_channels} channels.")
89
+ except Exception as e:
90
+ raise gr.Error(f"Can't read your file, the problem: {e}")
91
+
92
  # Rename the file
93
  old_wav_file = wav_file
94
  wav_file = "input.wav"