Update app.py
Browse files
app.py
CHANGED
@@ -28,57 +28,57 @@ from pydub import AudioSegment
|
|
28 |
# for p in predictions:
|
29 |
# col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
30 |
|
31 |
-
def read_as_single_channel_16k(audio_file, def_sr=16000, verbose=True, aim_second=None):
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
|
75 |
-
def my_read_file(audio_path, max_second):
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
82 |
|
83 |
def create_default_value():
|
84 |
if "def_value" not in st.session_state:
|
@@ -149,7 +149,7 @@ def main():
|
|
149 |
if add_watermark_button: # 点击按钮后执行的
|
150 |
if audio_file and watermark_text:
|
151 |
with st.spinner("Adding Watermark..."):
|
152 |
-
wav = my_read_file(wav,max_second_encode)
|
153 |
watermark = model.get_watermark(wav, default_sr)
|
154 |
# watermarked_audio, encode_time_cost = add_watermark(tmp_input_audio_file, watermark_text)
|
155 |
# st.write("Watermarked Audio:")
|
|
|
28 |
# for p in predictions:
|
29 |
# col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
30 |
|
31 |
+
# def read_as_single_channel_16k(audio_file, def_sr=16000, verbose=True, aim_second=None):
|
32 |
+
# assert os.path.exists(audio_file)
|
33 |
+
# st.markdown(os.path.exists(audio_file))
|
34 |
|
35 |
+
# file_extension = os.path.splitext(audio_file)[1].lower()
|
36 |
+
# st.markdown(file_extension)
|
37 |
+
|
38 |
+
# if file_extension == ".mp3":
|
39 |
+
# data, origin_sr = librosa.load(audio_file, sr=None)
|
40 |
+
# elif file_extension in [".wav", ".flac"]:
|
41 |
+
# data, origin_sr = soundfile.read(audio_file)
|
42 |
+
# else:
|
43 |
+
# raise Exception("unsupported file:" + file_extension)
|
44 |
+
|
45 |
+
# # channel check
|
46 |
+
# if len(data.shape) == 2:
|
47 |
+
# left_channel = data[:, 0]
|
48 |
+
# if verbose:
|
49 |
+
# print("Warning! the input audio has multiple chanel, this tool only use the first channel!")
|
50 |
+
# data = left_channel
|
51 |
+
|
52 |
+
# # sample rate check
|
53 |
+
# if origin_sr != def_sr:
|
54 |
+
# data = resampy.resample(data, origin_sr, def_sr)
|
55 |
+
# if verbose:
|
56 |
+
# print("Warning! The original samplerate is not 16Khz; the watermarked audio will be re-sampled to 16KHz")
|
57 |
+
|
58 |
+
# sr = def_sr
|
59 |
+
# audio_length_second = 1.0 * len(data) / sr
|
60 |
+
# # if verbose:
|
61 |
+
# # print("input length :%d second" % audio_length_second)
|
62 |
+
|
63 |
+
# if aim_second is not None:
|
64 |
+
# signal = data
|
65 |
+
# assert len(signal) > 0
|
66 |
+
# current_second = len(signal) / sr
|
67 |
+
# if current_second < aim_second:
|
68 |
+
# repeat_count = int(aim_second / current_second) + 1
|
69 |
+
# signal = np.repeat(signal, repeat_count)
|
70 |
+
# data = signal[0:sr * aim_second]
|
71 |
+
|
72 |
+
# return data, sr, audio_length_second
|
73 |
|
74 |
|
75 |
+
# def my_read_file(audio_path, max_second):
|
76 |
+
# signal, sr, audio_length_second = read_as_single_channel_16k(audio_path, default_sr)
|
77 |
+
# if audio_length_second > max_second:
|
78 |
+
# signal = signal[0:default_sr * max_second]
|
79 |
+
# audio_length_second = max_second
|
80 |
|
81 |
+
# return signal, sr, audio_length_second
|
82 |
|
83 |
def create_default_value():
|
84 |
if "def_value" not in st.session_state:
|
|
|
149 |
if add_watermark_button: # 点击按钮后执行的
|
150 |
if audio_file and watermark_text:
|
151 |
with st.spinner("Adding Watermark..."):
|
152 |
+
#wav = my_read_file(wav,max_second_encode)
|
153 |
watermark = model.get_watermark(wav, default_sr)
|
154 |
# watermarked_audio, encode_time_cost = add_watermark(tmp_input_audio_file, watermark_text)
|
155 |
# st.write("Watermarked Audio:")
|