0

I am working on reading audio files from three directories and calculate a PESQ score for these signals, sometimes this score cannot be calculated for some signals and give (Processing error!) how can I skip this error or signals and continue run the code.

My trial to add try and except if the result is not float number, pass but also not working

from pesq import pesq
from pystoi.stoi import stoi
import scipy.io.wavfile as wav
import numpy as np
import glob


for x, filename in enumerate(glob.glob('E:\eyFSC/**/*.wav')):
    print (x, filename)
    sr, mix = wav.read(filename) ##Why do you need this one btw, you never use it
    enhname=filename.replace('eyFSC','enFSC')
    sr, enh = wav.read(enhname)
    enhwname=filename.replace('eyFSC','enwFSC')
    sr,enhw= wav.read(enhwname)
    oriname=filename.replace('eyFSC','cFSC')
    sr,ori= wav.read(oriname)
    try:
        if type((pesq(16000, enh, mix, 'nb')) and (pesq(16000, enhw, mix, 'nb')) and (pesq(16000, ori, mix, 'nb'))) != float:
            print('Stop')
    except:
        pass

print('Scores are finished')

Here is the problem. The code stops after signal number 578 and doesn't complete.

577 E:\eyFSC\2ojo7YRL7Gck83Z3\94d4ddc0-45e0-11e9-81ce-69b74fd7e64e.wav
578 E:\eyFSC\2ojo7YRL7Gck83Z3\96202d00-45e1-11e9-81ce-69b74fd7e64e.wav
Processing error!
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Mohamed Nabih
  • 93
  • 1
  • 8
  • 2
    You code seems to be not indentated properly. – Rishabh Kumar Feb 13 '21 at 17:02
  • The code is not properly indented. – AcK Feb 13 '21 at 17:03
  • 1
    What does "not working" mean? – Sayse Feb 13 '21 at 17:03
  • 1
    We need more details. Is there an actual exception? If so, please provide it, including the traceback. Otherwise, what library are you using, and what is the error? Ideally you would provide a [mre], but it might be unnecessary to provide input and expected output. In any case, we do need the output. See [ask] if you want more tips. – wjandrea Feb 13 '21 at 17:08
  • 1
    Also, [a bare `except` is bad practice](https://stackoverflow.com/q/54948548/4518341). Instead, use the specific exception you're expecting like `except ProcessingError`, or at least `except Exception`. – wjandrea Feb 13 '21 at 17:09
  • You should not compare some result to a key word like float. even though the answer is a float value the 'if' conditions fails. The correct way to check if it is a float is `type(pesq(16000, enh, mix, 'nb')) != float`. Also in the above try block you are compering a boolean with a float. – SURYA TEJA Feb 13 '21 at 17:11
  • @ack I intended it correctly but it does still not working when the score cannot be computed – Mohamed Nabih Feb 13 '21 at 19:08
  • @Sayse the code stops and doesn't complete the scores of the remaining signals – Mohamed Nabih Feb 13 '21 at 19:09
  • @Sayse Can you see the questions I update it? – Mohamed Nabih Feb 13 '21 at 19:21

0 Answers0