pyAudioAnalysis
pyAudioAnalysis copied to clipboard
Example of how to print the results of speaker diarization instead of creating a plot?
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?
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 <script.py>:
(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>
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.