Spaces:
Build error
Build error
Commit
·
b487a20
1
Parent(s):
c9df9d1
Change to retrieve audio directly and not from file
Browse files
app.py
CHANGED
@@ -56,10 +56,8 @@ def populate_metadata(link):
|
|
56 |
return yt.thumbnail_url, yt.title, audio
|
57 |
|
58 |
def inference(yt_audio):
|
59 |
-
with open(yt_audio, "rb") as fd:
|
60 |
-
contents = fd.read()
|
61 |
|
62 |
-
audio = upload_audio(
|
63 |
|
64 |
est_ns = inference_model(audio)
|
65 |
|
@@ -105,7 +103,7 @@ with demo:
|
|
105 |
title = gr.Label(label="Video Title", placeholder="Title")
|
106 |
img = gr.Image(label="Thumbnail")
|
107 |
with gr.Row():
|
108 |
-
yt_audio = gr.Audio(
|
109 |
|
110 |
link.change(fn=populate_metadata, inputs=link, outputs=[img, title, yt_audio])
|
111 |
|
|
|
56 |
return yt.thumbnail_url, yt.title, audio
|
57 |
|
58 |
def inference(yt_audio):
|
|
|
|
|
59 |
|
60 |
+
audio = upload_audio(yt_audio,sample_rate=SAMPLE_RATE)
|
61 |
|
62 |
est_ns = inference_model(audio)
|
63 |
|
|
|
103 |
title = gr.Label(label="Video Title", placeholder="Title")
|
104 |
img = gr.Image(label="Thumbnail")
|
105 |
with gr.Row():
|
106 |
+
yt_audio = gr.Audio()
|
107 |
|
108 |
link.change(fn=populate_metadata, inputs=link, outputs=[img, title, yt_audio])
|
109 |
|
utils.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import tempfile
|
3 |
import collections
|
4 |
|
5 |
-
import
|
6 |
|
7 |
import pandas as pd
|
8 |
import matplotlib.pyplot as plt
|
@@ -13,51 +13,7 @@ class AudioIOReadError(BaseException): # pylint:disable=g-bad-exception-name
|
|
13 |
pass
|
14 |
|
15 |
def upload_audio(audio, sample_rate):
|
16 |
-
|
17 |
-
return wav_data_to_samples_librosa(audio, sample_rate=sample_rate)
|
18 |
-
|
19 |
-
def wav_data_to_samples_librosa(audio_file, sample_rate):
|
20 |
-
"""Loads an in-memory audio file with librosa.
|
21 |
-
Use this instead of wav_data_to_samples if the wav is 24-bit, as that's
|
22 |
-
incompatible with wav_data_to_samples internal scipy call.
|
23 |
-
Will copy to a local temp file before loading so that librosa can read a file
|
24 |
-
path. Librosa does not currently read in-memory files.
|
25 |
-
It will be treated as a .wav file.
|
26 |
-
Args:
|
27 |
-
audio_file: Wav file to load.
|
28 |
-
sample_rate: The number of samples per second at which the audio will be
|
29 |
-
returned. Resampling will be performed if necessary.
|
30 |
-
Returns:
|
31 |
-
A numpy array of audio samples, single-channel (mono) and sampled at the
|
32 |
-
specified rate, in float32 format.
|
33 |
-
Raises:
|
34 |
-
AudioIOReadException: If librosa is unable to load the audio data.
|
35 |
-
"""
|
36 |
-
with tempfile.NamedTemporaryFile(suffix='.wav') as wav_input_file:
|
37 |
-
wav_input_file.write(audio_file)
|
38 |
-
# Before copying the file, flush any contents
|
39 |
-
wav_input_file.flush()
|
40 |
-
# And back the file position to top (not need for Copy but for certainty)
|
41 |
-
wav_input_file.seek(0)
|
42 |
-
return load_audio(wav_input_file.name, sample_rate)
|
43 |
-
|
44 |
-
def load_audio(audio_filename, sample_rate, duration=10):
|
45 |
-
"""Loads an audio file.
|
46 |
-
Args:
|
47 |
-
audio_filename: File path to load.
|
48 |
-
sample_rate: The number of samples per second at which the audio will be
|
49 |
-
returned. Resampling will be performed if necessary.
|
50 |
-
Returns:
|
51 |
-
A numpy array of audio samples, single-channel (mono) and sampled at the
|
52 |
-
specified rate, in float32 format.
|
53 |
-
Raises:
|
54 |
-
AudioIOReadError: If librosa is unable to load the audio data.
|
55 |
-
"""
|
56 |
-
try:
|
57 |
-
y, unused_sr = librosa.load(audio_filename, sr=sample_rate, mono=True, duration=duration)
|
58 |
-
except Exception as e: # pylint: disable=broad-except
|
59 |
-
raise AudioIOReadError(e)
|
60 |
-
return y
|
61 |
|
62 |
# Generate piano_roll
|
63 |
def sequence_to_pandas_dataframe(sequence):
|
|
|
2 |
import tempfile
|
3 |
import collections
|
4 |
|
5 |
+
import note_seq
|
6 |
|
7 |
import pandas as pd
|
8 |
import matplotlib.pyplot as plt
|
|
|
13 |
pass
|
14 |
|
15 |
def upload_audio(audio, sample_rate):
|
16 |
+
return note_seq.audio_io.wav_data_to_samples_librosa(audio, sample_rate=sample_rate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Generate piano_roll
|
19 |
def sequence_to_pandas_dataframe(sequence):
|