Re: creating status sounds in python

One file or 100 files probably amounts to the same. Maybe you can use a tool like sox to generate all the files with a loop from a script. A command is for example:
sox.exe -n output.wav synth .2 sine 300
http://sox.sourceforge.net/

In theory you can use pygame to synthesize the sounds but I couldn't make them sound right. The following example should be sine waves and it probably doesn't loop well.

import time

import numpy
import pygame


sample_rate = 44100

def sine(hz):
    length = sample_rate / float(hz)
    omega = numpy.pi * 2 / length
    a = numpy.sin(numpy.arange(int(length)) * omega)
    aa = numpy.column_stack((a, a))
    return pygame.sndarray.make_sound(aa)

def play_sine(hz, d):
    sound = sine(hz)
    sound.play(loops=-1)
    time.sleep(d)
    sound.stop()
    
def main():
    pygame.mixer.pre_init(sample_rate, -16, 2) # 44.1kHz, 16-bit signed, stereo
    pygame.init()
    sounds = (sine(i) for i in range(330,550))
    for sound in sounds:
        sound.play(loops=-1)
        time.sleep(.07)
        sound.stop()

##    for f in range(330, 550):
##        play_sine(f, .07)

if __name__ == '__main__': main()
_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : tward via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector

Reply via email to