Home > other >  Audiomath TypeError - MakeRise, MakeFade, MakeHannWindow
Audiomath TypeError - MakeRise, MakeFade, MakeHannWindow

Time:09-28

I'm using audiomath under Python 3.7 on Windows 10.

I have been using audiomath to standardize my audio files for EEG analyses, it has been very useful for all parameters except this one, I keep stuck when trying to make it create fade-ins, fade-outs or HannWindows.

I've run the same code on other machines with other versions of Python and Numpy and I still get the same error.

from audiomath import Sound, MakeRise
import numpy

sound01 = Sound('mySample.wav')
soundFadedIn = sound01.MakeHannWindow(5)
soundFadedIn.Play()

Log Error

CodePudding user response:

As pointed out by @WarrenWeckesser, this was a bug in audiomath, which has been fixed in audiomath version 1.16.0

Note that MakeHannWindow only returns the Hann weighting itself (with duration and sampling-frequency matched to sound01). It does not return the sound multiplied by the weighting as you seem to have assumed. What you seem to be trying to do may be better accomplished using the .Fade() method (which was also affected by the same bug).

With a little modification, the way you did it is one way to do it (it always gives you a symmetric fade-in and -out, optionally specifying the duration of the plateau in the middle, in seconds):

from audiomath import Sound

sound01 = Sound('mySample.wav')
soundFadedInAndOut = sound01 * sound01.MakeHannWindow(5)  # note the multiplication

Or here's another, where you specify the duration of the rising and falling sections explicitly and separately, instead (it doesn't have to be symmetric, and either of the two durations can be 0):

from audiomath import Sound

sound01 = Sound('mySample.wav')
soundFadedInAndOut = sound01.Copy().Fade(risetime=0.5, falltime=0.5, hann=True)

Finally, if for some reason you're unable or unwilling to upgrade audiomath to 1.16, a workaround for the bug you're reporting might be to use the Shoulder() function from audiomath.Signal to generate your windowing function:

import audiomath as am, numpy as np

x = am.Sound('mySample.wav')
endFadeIn, startFadeOut = 0.5, x.duration-0.5
t = np.linspace(0, x.duration, x.nSamples) # in seconds
window = am.Signal.Shoulder(t, [0, endFadeIn, startFadeOut, x.duration])  # it's a numpy array, not a Sound
faded = x * window   # but you can still multiply a Sound by it
faded.Play()
  • Related