horiyouta commited on
Commit
49ef738
1 Parent(s): fbdd0fa

202406211405

Browse files
Files changed (2) hide show
  1. app.py +16 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr, soundfile as sf, io
2
+ from pydub import AudioSegment
3
+
4
+ def audio_to_audiosegment(audio):
5
+ sample_rate, audio_data = audio
6
+ temp_wav = io.BytesIO()
7
+ sf.write(temp_wav, audio_data, sample_rate, format='WAV')
8
+ temp_wav.seek(0)
9
+ [aud, vol, res] = [AudioSegment.from_file(temp_wav, format="wav"), [], '']
10
+ for i in range(int(len(aud) / 33)):
11
+ frame = aud[i * 33 : (i + 1) * 33]
12
+ vol.append(frame.dBFS)
13
+ for v in vol: res += str([v < -50, -50 <= v and v < -30, -30 <= v and v < -20, -20 <= v and v < -10, -10 <= v].index(True) + 1)
14
+ return res
15
+
16
+ gr.Interface(fn=audio_to_audiosegment, inputs=gr.Audio(type="numpy"), outputs="text", title="口パク データ変換").launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ soundfile
2
+ pydub