tyiannak / pyAudioAnalysis

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications
Apache License 2.0
5.83k stars 1.19k forks source link

Example of how to print the results of speaker diarization instead of creating a plot? #327

Open l0ophole opened 3 years ago

l0ophole commented 3 years ago

I tried changing plot_res to False but nothing is printed when I run speaker diarization on the command line like so:

python3 audioAnalysis.py speakerDiarization -i test1.wav --num 0

Can someone give me an example of what I need to change in the python file to print the timestamps of the different speakers or give me an example of how to import the python library and run the speaker diarization function to print the results to the console?

l0ophole commented 3 years ago

I figured it out. Here is an example python script if anyone is interested. The other issues that deal with this problem mention using flags2segs but apparently than function has been changed to labels_to_segments.

To use this script, you can do this if you're using the bash shell. Otherwise just paste the python script into a file and chmod +x to make it executable, or run it with python3 :

(cat << 'EOF'
#!/usr/bin/env python3
from pyAudioAnalysis import audioSegmentation as aS
import sys

cls = aS.speaker_diarization(sys.argv[1], n_speakers=int(sys.argv[2]), lda_dim=0, plot_res=False)
segs,flags = aS.labels_to_segments(cls, 0.2)
for s in range(segs.shape[0]):
    print("{} {} {}".format(segs[s,0], segs[s,1], flags[s]))
EOF
) > sd.py
chmod +x sd.py

Then run it like this: ./sd.py <audio.wav> <number_of_speakers>

ryanfox commented 3 years ago

The other issues that deal with this problem mention using flags2segs but apparently than function has been changed to labels_to_segments.

Wanted to highlight this - a lot of other open issues reference flags2segs. Took me a while to figure out why I couldn't find that function.