beetbox / audioread

cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python
MIT License
481 stars 108 forks source link

FFMPEG installed but no backend error is still occuring #45

Closed mv00147 closed 7 years ago

mv00147 commented 7 years ago

Dear sir/madam, Audio read raised the no backend error. So, I installed ffmpeg on my computer and verified its installation too. But when I run my code in the ipython console, I still get the No Backend error. What should I do?

sampsyo commented 7 years ago

Hi! Can you please provide full details about what exactly you're doing (i.e., which code you're running) and the exact output you're getting? It would also be very helpful if you could try running things outside of IPython, just in case.

Here's some general advice about how to write a good bug report.

mv00147 commented 7 years ago

Hello, Thank you for your reply. I am trying to run the following code.

 import time
import numpy as np
from keras import backend as K
from music_tagger_cnn import MusicTaggerCNN
from music_tagger_crnn import MusicTaggerCRNN
import audio_processor as ap
import pdb

##
def sort_result(tags, preds):
    result = zip(tags, preds)
    sorted_result = sorted(result, key=lambda x: x[1], reverse=True)
    return [(name, '%5.3f' % score) for name, score in sorted_result]

def librosa_exists():
    try:
        __import__('librosa')
    except ImportError:
        return False
    else:
        return True

def main(net):

    print('Running main() with network: %s and backend: %s' % (net, K._BACKEND))
    # setting
    audio_paths = ['data/bensound-cute.mp3',
                   'data/bensound-actionable.mp3',
                   'data/bensound-dubstep.mp3',
                   'data/bensound-thejazzpiano.mp3']
    melgram_paths = ['data/bensound-cute.npy',
                     'data/bensound-actionable.npy',
                     'data/bensound-dubstep.npy',
                     'data/bensound-thejazzpiano.npy']

    tags = ['rock', 'pop', 'alternative', 'indie', 'electronic',
            'female vocalists', 'dance', '00s', 'alternative rock', 'jazz',
            'beautiful', 'metal', 'chillout', 'male vocalists',
            'classic rock', 'soul', 'indie rock', 'Mellow', 'electronica',
            '80s', 'folk', '90s', 'chill', 'instrumental', 'punk',
            'oldies', 'blues', 'hard rock', 'ambient', 'acoustic',
            'experimental', 'female vocalist', 'guitar', 'Hip-Hop',
            '70s', 'party', 'country', 'easy listening',
            'sexy', 'catchy', 'funk', 'electro', 'heavy metal',
            'Progressive rock', '60s', 'rnb', 'indie pop',
            'sad', 'House', 'happy']

    # prepare data like this
    melgrams = np.zeros((0, 1, 96, 1366))

    if librosa_exists:
        for audio_path in audio_paths:
            melgram = ap.compute_melgram(audio_path)
            melgrams = np.concatenate((melgrams, melgram), axis=0)
    else:
        for melgram_path in melgram_paths:
            melgram = np.load(melgram_path)
            melgrams = np.concatenate((melgrams, melgram), axis=0)

    # load model like this
    if net == 'cnn':
        model = MusicTaggerCNN(weights='msd')
    elif net == 'crnn':
        model = MusicTaggerCRNN(weights='msd')

    # predict the tags like this
    print('Predicting...')
    start = time.time()
    pred_tags = model.predict(melgrams)
    # print like this...
  #  print "Prediction is done. It took %d seconds." % (time.time()-start)
    print('Printing top-10 tags for each track...')
    for song_idx, audio_path in enumerate(audio_paths):
        sorted_result = sort_result(tags, pred_tags[song_idx, :].tolist())
        print(audio_path)
        print(sorted_result[:5])
        print(sorted_result[5:10])
        print(' ')

    return

if __name__ == '__main__':

    networks = ['cnn', 'crnn']
    for net in networks:
        main(net)

When I execute this on the i-python console, the noBackend Error gets raised. So I installed ffmpeg. The audio read is being used to do the melgram computation and it still raises the same error despite ffmpeg being installed.

sampsyo commented 7 years ago

Please include the actual output of running this code. Specifically, save your code in test.py, execute python test.py from the console, and include the output.

Also, please try using the audioread module directly instead of through those other libraries above.

Also, are you certain that the ffmpeg command is installed and available on your PATH? You can try running ffmpeg -version from the console.

mv00147 commented 7 years ago

Hi, Yes I have checked the version. Thats how I verified the installation of ffmpeg. How can I run audioread directly? Sorry, I didnt catch that point?

mv00147 commented 7 years ago

Hi, Thanks seems to be running on the console :)