Guest User

Convert riffusion image to a .wav file

a guest
Dec 15th, 2022
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. from audio import *
  2. from sys import argv
  3. from PIL import Image
  4. import wave
  5.  
  6. f = Image.open(argv[1])
  7. wav_bytes, duration_s = wav_bytes_from_spectrogram_image(f)
  8. wav_bytes = wav_bytes.read()
  9.  
  10. print(duration_s)
  11.  
  12. # Open a new wave file
  13. with wave.open('myfile.wav','wb') as wf:
  14. # Set the number of channels, sample width, and sample rate
  15. wf.setnchannels(1)
  16. wf.setsampwidth(2)
  17. wf.setframerate(44100)
  18. # Write the audio data to the file
  19. wf.writeframes(wav_bytes)
  20.  
Advertisement
Add Comment
Please, Sign In to add comment