vBaiCai / python-pesq

A python package for calculating the PESQ.
MIT License
353 stars 69 forks source link

ValueError #29

Closed thijsdeschildre closed 4 months ago

thijsdeschildre commented 4 months ago

with python 3.10, I use the example script:

import soundfile as sf
from pypesq import pesq

ref, sr = sf.read("ref.wav")
deg, sr = sf.read("deg.wav")

score = pesq(ref, deg, sr)
print(score)

and get the error

Traceback (most recent call last):
  File "/home/lattepanda/Documents/pesq3.py", line 7, in <module>
    score = pesq(ref, deg, sr)
  File "/home/lattepanda/.local/lib/python3.10/site-packages/pypesq/__init__.py", line 21, in pesq
    max_sample = np.max(np.abs(np.array([ref, deg])))
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

info about both files:

sox --i ref.wav

Input File     : 'ref.wav'
Channels       : 1
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:00:51.03 = 408226 samples ~ 3827.12 CDDA sectors
File Size      : 816k
Bit Rate       : 128k
Sample Encoding: 16-bit Signed Integer PCM
sox --i deg.wav

Input File     : 'deg.wav'
Channels       : 2
Sample Rate    : 8000
Precision      : 16-bit
Duration       : 00:00:50.54 = 404301 samples ~ 3790.32 CDDA sectors
File Size      : 1.62M
Bit Rate       : 256k
Sample Encoding: 16-bit Signed Integer PCM
vBaiCai commented 4 months ago

Hi, I think the deg.wav and ref.wav should be mono-channel audio.

thijsdeschildre commented 4 months ago

Hi, I think the deg.wav and ref.wav should be mono-channel audio.

thanks, good pointer but no luck. do you have any sample files that should work?

vBaiCai commented 4 months ago

import soundfile as sf
from pypesq import pesq
import numpy as np

# ref, sr = sf.read("ref.wav")
# deg, sr = sf.read("deg.wav")
sr = 16000

ref = np.random.uniform(-1, 1, 16000 * 10)
deg = np.random.uniform(-1, 1, 16000 * 10)

score = pesq(ref, deg, sr)
print(score)

you can try dummy input data.

thijsdeschildre commented 4 months ago

yeah, that works. no idea what is wrong with my input data. files have the same length and the audio is somewhat aligned. or does it need perfect syncing?

thijsdeschildre commented 4 months ago

OK, found it. I had to use a tool to cut both files to exactly the same length. now it works.