0

I want to make a small app that plays a sound every time i press a button, but the sounds have a small delay because they have to load from the SD (i think). Is there any way to upload the audio files to RAM memory every time i run the code, or any other idea to get rid of that delay?

Thank you!

import pygame
pygame.init()

doSound = pygame.mixer.Sound('/mnt/ramdisk/do.wav')

doSound.play()
THIFT
  • 33
  • 7
  • 1
    Could you please share the relevant code? https://stackoverflow.com/help/how-to-ask – Sebastian Nov 27 '18 at 14:35
  • You could try a RAMdisk: `mount -t tmpfs -o size=16m tmpfs /mnt/ramdisk` and copy your sound file to `/mnt/ramdisk` – Mark Setchell Nov 27 '18 at 14:42
  • code added, sorry for that @Sebastian – THIFT Nov 27 '18 at 16:51
  • I don't think this works... There is no difference. Or maybe i did something wrong. @MarkSetchell – THIFT Nov 27 '18 at 17:08
  • You could try convert wav to a numpy array (so it is loaded at start time) when you start your app and then play it. Some relevant links to start are [this](https://stackoverflow.com/questions/16778878/python-write-a-wav-file-into-numpy-float-array) and [this](https://stackoverflow.com/questions/10357992/how-to-generate-audio-from-a-numpy-array). – miimote Nov 27 '18 at 19:38
  • Solved! Link to the answer that worked for me [here](https://stackoverflow.com/questions/18273722/pygame-sound-delay) – THIFT Nov 29 '18 at 14:30

0 Answers0