|
import gradio as gr, soundfile as sf, io |
|
from pydub import AudioSegment |
|
|
|
def audio_to_audiosegment(audio): |
|
sample_rate, audio_data = audio |
|
temp_wav = io.BytesIO() |
|
sf.write(temp_wav, audio_data, sample_rate, format='WAV') |
|
temp_wav.seek(0) |
|
[aud, vol, res] = [AudioSegment.from_file(temp_wav, format="wav"), [], ''] |
|
for i in range(int(len(aud) / 33)): |
|
frame = aud[i * 33 : (i + 1) * 33] |
|
vol.append(frame.dBFS) |
|
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) |
|
return res |
|
|
|
gr.Interface(fn=audio_to_audiosegment, inputs=gr.Audio(type="numpy"), outputs="text", title="口パク データ変換").launch() |