Jellevanderwerff / thebeat

thebeat: Rhythms in Python for science
https://thebeat.readthedocs.io
GNU General Public License v3.0
19 stars 1 forks source link

SoundStimulus.from_parselmouth results in unwriteable (but playable) SoundStimulus object #83

Closed Jellevanderwerff closed 6 months ago

Jellevanderwerff commented 6 months ago

After f63e405 the following code raises an error:

from parselmouth import Sound
import thebeat

sound = Sound("u.wav")

seq = thebeat.Sequence([500])

trial = thebeat.SoundSequence(thebeat.SoundStimulus.from_parselmouth(sound), seq)
trial.write_wav("test.wav")
Traceback (most recent call last):
  File "/Users/jellevanderwerff/ssf_presentation/scratch.py", line 22, in <module>
    trial.write_wav("test.wav")
  File "/Users/jellevanderwerff/thebeat/thebeat/core/soundsequence.py", line 472, in write_wav
    thebeat.helpers.write_wav(
  File "/Users/jellevanderwerff/thebeat/thebeat/helpers.py", line 721, in write_wav
    wavfile.write(filename=filepath, rate=fs, data=samples)
  File "/Users/jellevanderwerff/ssf_presentation/venv/lib/python3.9/site-packages/scipy/io/wavfile.py", line 797, in write
    fmt_chunk_data = struct.pack('<HHIIHH', format_tag, channels, fs,
struct.error: required argument is not an integer
Jellevanderwerff commented 6 months ago

Also happens without thebeat:

from parselmouth import Sound
from scipy.io import wavfile

sound = Sound("u.wav")

fs = sound.sampling_frequency
samples = sound.values[0]

wavfile.write("u_out.wav", fs, samples)

results in:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jellevanderwerff/ssf_presentation/venv/lib/python3.9/site-packages/scipy/io/wavfile.py", line 797, in write
    fmt_chunk_data = struct.pack('<HHIIHH', format_tag, channels, fs,
struct.error: required argument is not an integer
Jellevanderwerff commented 6 months ago

Was due to the sampling frequency in Praat being a floating-point number which scipy couldn't handle. Fixed in 3948729.