Shingome commited on
Commit
bb986e3
·
1 Parent(s): 27b08c6

initial commit

Browse files
Files changed (4) hide show
  1. app.py +24 -0
  2. requirements.txt +3 -0
  3. src/convertation.py +14 -0
  4. src/multiply_audio.py +10 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.multiply_audio import multiply_audio
3
+ from src.convertation import np_to_audio
4
+
5
+
6
+ def sentence_builder(audio, count: int, offset: float):
7
+ raw_audio = np_to_audio(audio[0], audio[1])
8
+ file = "sound.mp3"
9
+ multiply_audio(raw_audio, count, offset * 1000.).export(file)
10
+ return file
11
+
12
+
13
+ if __name__ == "__main__":
14
+ iface = gr.Interface(
15
+ sentence_builder,
16
+ [
17
+ "audio",
18
+ gr.Slider(1, 1000, step=1, value=1, label="Count"),
19
+ gr.Slider(0, 10, step=0.05, value=0, label="Offset")
20
+ ],
21
+ "audio"
22
+ )
23
+
24
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==4.31.5
2
+ numpy==1.26.4
3
+ pydub==0.25.1
src/convertation.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from pydub import AudioSegment
3
+
4
+
5
+ def np_to_audio(sr, x):
6
+ def normalize_audio(x):
7
+ return x / np.max(np.abs(x))
8
+
9
+ channels = 2 if (x.ndim == 2 and x.shape[1] == 2) else 1
10
+
11
+ x = normalize_audio(x)
12
+ y = np.int16(x * 2 ** 15)
13
+
14
+ return AudioSegment(y.tobytes(), frame_rate=sr, sample_width=2, channels=channels)
src/multiply_audio.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pydub import AudioSegment
3
+
4
+
5
+ def multiply_audio(audio: AudioSegment, count: int, offset: float, progress=gr.Progress()):
6
+ audio_result = AudioSegment.silent(audio.duration_seconds * 1000. + offset * count)
7
+ for i in progress.tqdm(range(count), desc="Processing"):
8
+ audio_result = audio_result.overlay(audio, position=i * offset)
9
+
10
+ return audio_result