Regarding inability of Python Module Winsound to produce beep in decimal frequency

Terry Reedy tjreedy at udel.edu
Fri Aug 13 11:46:30 EDT 2021


On 8/13/2021 6:53 AM, Umang Goswami wrote:
> Hi There, Hope you find this mail in good health.
> 
> I am Umang Goswami, a Python developer and student working on a huge
> project for automation of music instruments. I am producing the musical
> notes using the Beep function of Winsound Module(
> https://docs.python.org/3/library/winsound.html) by passing frequency as a
> argument to the function.
> 
> Now whenever i provide frequency of any note in decimal(for example
> 277.1826 for C4 note) it shows following error:
> Traceback (most recent call last):
>    File "C:\Users\Umang Goswami\Desktop\Umang  Goswami\test.py", line 2, in
> <module>
>      winsound.Beep(111.11,111111)
> TypeError: integer argument expected, got float
> 
> Now I have  to round up the frequencies. This is hurting the quality,
> accuracy ,authenticity and future of the project. Almost all the notes have
> the frequencies  in decimal parts. Rounding up means changing semitones and
> quatertones thus whole note itself. This problem is technically making my
> program useless.
> 
> Its my humble request to you all, I beg you, Please tell me how to overcome
> this issue. I have consulted many sources both online and offline but I
> remained unsatisfied. I can not make audio files of each note because there
> are many many notes and so practically making so many files of different
> time length wont help.
> 
> Please suggest to me the way to resolve this issue or is there any other
> module to produce the sound of decimal frequency.

Without knowing what sources you have already looked at, anything anyone 
might say might be duplication.  However,...

If the builtin hardware sound generator only generates integral 
frequencies, you are stuck unless you get an add-in card that is more 
flexible.  If the Windows interface to the hardware only accepts 
integral frequencies, which I suspect might be true, ditto, unless you 
get custom software.  You could look at pygame and see what its sound 
functions do.  And search pypi for 'sound generator' or 'frequency 
generator'.

-- 
Terry Jan Reedy



More information about the Python-list mailing list