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

Is it possible to detect all the chords in a single audio file? #8

Open
pallocchi opened this issue Jan 23, 2023 · 1 comment
Open

Comments

@pallocchi
Copy link

pallocchi commented Jan 23, 2023

Hi! I'm using the library as the documentation explains:

String pathFile = "/path/to/file.wav";
Signal signal = new WAVFile(new File(pathFile)).getSamples(0);

try (ChordPredictor predictor = ChordPredictor.getInstance()) {
    String chord = predictor.predict(CRPVectorFactory.from_signal(signal));
    System.out.println("Predicted chord: "+chord);
}

My audio file is 28 seconds long, and it has ~20 guitar chords.
However, the predictor was able to detect 1 chord only.
Since the predict method returns just a string, I guess I'm using it wrong.
How should I use the library for this use case?

Thanks,

@nojux-official
Copy link

Your code just predicts a chord from all samples.

I modified the CLIChordRecognizer example to extract chords from wav file instead of a microphone and my code is:

import com.github.zukarusan.jchoreco.system.ChordProcessor;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

import javax.sound.sampled.UnsupportedAudioFileException;
import be.tarsos.dsp.AudioDispatcher;
import be.tarsos.dsp.io.jvm.AudioDispatcherFactory;

public class ExtractFromWav {
    static final float SAMPLE_RATE = 44100;
    static final int BUFFER_SIZE = 44100;
    static Thread chordThread = null;

    public static void main(String[] args) throws IOException, UnsupportedAudioFileException {
        ChordProcessor.isDebug = false;

        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter file path:");
        String fileName = scanner.nextLine();

        System.out.println("Processing: " + fileName);
        File file = new File(fileName);
        AudioDispatcher dispatcher = AudioDispatcherFactory.fromFile(file, BUFFER_SIZE, BUFFER_SIZE / 2);

        PrintStream output_chords = new PrintStream(System.out);
        ChordProcessor chordProcessor = new ChordProcessor(SAMPLE_RATE, BUFFER_SIZE, output_chords);
        dispatcher.addAudioProcessor(chordProcessor);

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Releasing Resources");
            chordProcessor.close();
        }));


        chordThread = new Thread(dispatcher, "Chord recognizer");
        chordThread.start();

        while (chordThread.isAlive()) {
        }

        chordThread.interrupt();
        dispatcher.stop();
        chordProcessor.close();
        System.exit(0);
    }
}

Still, this code needs some changes, but I think it can be a starting point.

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

2 participants