0

I have a github repo that i opened in jupyter lab.

The main file .py needs other files, it gives me error when i run it in jupyter cell.

# %load ML-SpeakerDiarization/speaker/demo/demo_diarization.py
from speaker.model.speaker_diarization import speaker_diarization
from speaker.utils.utils import read_wav


def todiarize(input):
    fs, signal = read_wav(input)
    n, cls, sp, z = speaker_diarization(fs, signal)
    return {
        'filename': z,
        'nspeaker': n,
        'sp': sp
    }

if __name__=="__main__":
    todiarize("C:\\Users\\OUKAJA\\Desktop\\oishi-master\\uploads\\1.wav")

The error is:

ModuleNotFoundError: No module named 'speaker'

but speaker is a dir with 3 nested folders and some py files in them, not 1 file.

ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • 3
    Do you really want to _run_ all the files in the repo (as your title says) or is it just about running the main file, for which it'll need to import some of the others? – mrks Jan 21 '20 at 11:48
  • @mrks, right! i just need to run the main file , but main file needs other files to be imported(?) or 'compiled'.. – ERJAN Jan 22 '20 at 08:40

1 Answers1

1

The module speaker, from which you're trying to import from is not found, and hence, none of it's submodules. I assume that you did clone/download the entire repository.

Check if the folder containing speaker is in your python path, e.g. like this:

import sys
for path in sys.path:
    print(path)

If it's not, an quick and dirty workaround could be to add it manually in the script:

...

sys.path.append('SOME/PATH/to/ML-SpeakerDiarization')

import speaker  # should work now.

That being said, adding paths manually is ugly. Consider writing a setup.py for your project such that you can install it properly. With this, you can also handle dependencies smoothly. This might help you getting started.

mrks
  • 513
  • 3
  • 7