cvqluu / simple_diarizer

Simplified diarization pipeline using some pretrained models - audio file to diarized segments in a few lines of code
GNU General Public License v3.0
141 stars 27 forks source link

waveplot_perspeaker causes argument out of range error #10

Closed ZQ-Dev8 closed 10 months ago

ZQ-Dev8 commented 2 years ago

While running through your code example, testing the workflow on a different audio file produced the following output:

C:\Users\xxx\Miniconda3\envs\simple_diarizer_env\lib\site-packages\IPython\lib\display.py:187: RuntimeWarning: invalid value encountered in divide
  scaled = data / normalization_factor * 32767
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
Cell In [18], line 1
----> 1 waveplot_perspeaker(signal, fs, segments)

File ~\Miniconda3\envs\simple_diarizer_env\lib\site-packages\simple_diarizer\utils.py:166, in waveplot_perspeaker(signal, fs, segments)
    164 if "words" in seg:
    165     pprint(seg["words"])
--> 166 display(Audio(speech, rate=fs))
    167 print("=" * 40 + "\n")

File ~\Miniconda3\envs\simple_diarizer_env\lib\site-packages\IPython\lib\display.py:130, in Audio.__init__(self, data, filename, url, embed, rate, autoplay, normalize, element_id)
    128 if rate is None:
    129     raise ValueError("rate must be specified when data is a numpy array or list of audio samples.")
--> 130 self.data = Audio._make_wav(data, rate, normalize)

File ~\Miniconda3\envs\simple_diarizer_env\lib\site-packages\IPython\lib\display.py:162, in Audio._make_wav(data, rate, normalize)
    160 waveobj.setsampwidth(2)
    161 waveobj.setcomptype('NONE','NONE')
--> 162 waveobj.writeframes(scaled)
    163 val = fp.getvalue()
    164 waveobj.close()

File ~\Miniconda3\envs\simple_diarizer_env\lib\wave.py:437, in Wave_write.writeframes(self, data)
    436 def writeframes(self, data):
--> 437     self.writeframesraw(data)
    438     if self._datalength != self._datawritten:
    439         self._patchheader()

File ~\Miniconda3\envs\simple_diarizer_env\lib\wave.py:426, in Wave_write.writeframesraw(self, data)
    424 if not isinstance(data, (bytes, bytearray)):
    425     data = memoryview(data).cast('B')
--> 426 self._ensure_header_written(len(data))
    427 nframes = len(data) // (self._sampwidth * self._nchannels)
    428 if self._convert:

File ~\Miniconda3\envs\simple_diarizer_env\lib\wave.py:467, in Wave_write._ensure_header_written(self, datasize)
    465 if not self._framerate:
    466     raise Error('sampling rate not specified')
--> 467 self._write_header(datasize)

File ~\Miniconda3\envs\simple_diarizer_env\lib\wave.py:479, in Wave_write._write_header(self, initlength)
    477 except (AttributeError, OSError):
    478     self._form_length_pos = None
--> 479 self._file.write(struct.pack('<L4s4sLHHLLHH4s',
    480     36 + self._datalength, b'WAVE', b'fmt ', 16,
    481     WAVE_FORMAT_PCM, self._nchannels, self._framerate,
    482     self._nchannels * self._framerate * self._sampwidth,
    483     self._nchannels * self._sampwidth,
    484     self._sampwidth * 8, b'data'))
    485 if self._form_length_pos is not None:
    486     self._data_length_pos = self._file.tell()

error: argument out of range

Any ideas what the issue could be? It works fine on other audio files, and everything up to this point seems to run without error.

cvqluu commented 1 year ago

Hi, could you post the dimensions/shapes/lens of the following variables?:

signal
segments