简体   繁体   中英

Pygame mixer on Raspberry Pi

I'm trying to play soud on Raspberry using Pygame. I can ear the sound, the problem is that I got a background noise (like someone's breathing in a mic) as soon as I run the script. The code is very simple :

import pygame.mixer
import os
import sys
import time
pygame.mixer.init(frequency=48000, size=-16, channels=1, buffer=1024)
pygame.mixer.music.load('path/to/file.ogg')
pygame.mixer.music.play()

I found the inits values on another forum, I tried many others, same result. I also tried to use :

sound = pygame.mixer.Sound('path/to/file.ogg')
sound.play()

Same result. Any ideas ?

Thanks in advance

The default buffer's valor is 3072. If this number is smaller than it, the sound can lost quality.

In the official documentation is written:

The buffer argument controls the number of internal samples used in the sound mixer. The default value should work for most cases. It can be lowered to reduce latency, but sound dropout may occur. It can be raised to larger values to ensure playback never skips, but it will impose latency on sound playback. The buffer size must be a power of two (if not it is rounded up to the next nearest power of 2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM