File size: 724 Bytes
49ef738 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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() |