Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real time tempo detection #20

Open
marestudio2004 opened this issue Nov 25, 2023 · 1 comment
Open

Real time tempo detection #20

marestudio2004 opened this issue Nov 25, 2023 · 1 comment

Comments

@marestudio2004
Copy link

Hi, can I apply your library in realtime tempo detection?
So signal will be recorded in frames and send in model somthing like in Local tempo estimation...
Do you have any recommendation, frame length...and is this possible at all or does the complete audio file have to be loaded?
This is my code which does not work:
`from tempocnn.classifier import TempoClassifier
from tempocnn.feature import read_features
import pyaudio
import numpy as np
from librosa import util

model_name = 'cnn'
classifier = TempoClassifier(model_name)

chunk = 2048
sample_format = pyaudio.paInt16
channels = 1
fs = 11025 # frames per channel
seconds = 50
p=pyaudio.PyAudio()
print("Recording ...")
stream = p.open(format = sample_format,
channels = channels,
rate = fs,
frames_per_buffer = chunk,
input = True)

for i in range(0, int(fs/chunk * seconds)):
data = stream.read(chunk)
data_pcm = util.buf_to_float(data, dtype=np.float32)
features = read_features(data_pcm, frames=256, hop_length=32)
# estimate local tempi, this returns tempo classes, i.e., a distribution
local_tempo_classes = classifier.estimate(features)
# find argmax per frame and convert class index to BPM value
max_predictions = np.argmax(local_tempo_classes, axis=1)
local_tempi = classifier.to_bpm(max_predictions)
print(f"Estimated local tempo classes: {local_tempi}")

stream.stop_stream()
stream.close()
p.terminate()
print("... Ending Recording")
`

@marestudio2004
Copy link
Author

I change the function feature.py, line 34 is under the comment and I add y as audio data and sr as sample rate:

`# y, sr = librosa.load(file, sr=11025) # marko

y = file # marko
sr = 11025 # marko

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant