Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

sound_gen3.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import pyaudio
  2. import wave
  3. import sys
  4. # length of data to read.
  5. chunk = 1024
  6. # validation. If a wave file hasn't been specified, exit.
  7. if len(sys.argv) < 2:
  8. print "Plays a wave file.\n\n" +\
  9. "Usage: %s filename.wav" % sys.argv[0]
  10. sys.exit(-1)
  11. '''
  12. ************************************************************************
  13. This is the start of the "minimum needed to read a wave"
  14. ************************************************************************
  15. '''
  16. # open the file for reading.
  17. wf = wave.open(sys.argv[1], 'rb')
  18. # create an audio object
  19. p = pyaudio.PyAudio()
  20. # open stream based on the wave object which has been input.
  21. stream = p.open(format =
  22. p.get_format_from_width(wf.getsampwidth()),
  23. channels = wf.getnchannels(),
  24. rate = wf.getframerate(),
  25. output = True)
  26. # read data (based on the chunk size)
  27. data = wf.readframes(chunk)
  28. # play stream (looping from beginning of file to the end)
  29. while data != '':
  30. # writing to the stream is what *actually* plays the sound.
  31. stream.write(data)
  32. data = wf.readframes(chunk)
  33. # cleanup stuff.
  34. stream.close()
  35. p.terminate()