如何调整 Pygame 中特定音频通道的音量?

How do I adjust the volume of a specific audio channel in Pygame?

您只需调整 pygame.mixer.Channel(0)

中此背景音轨(特定音频通道“0”)的音量

该程序使用它和不使用它都可以工作pygame.mixer.music.set_volume (0.1)

此外,在 pygame.mixer.music.set_volume (0.1) 的帮助下,无需通过 mixer.music.load("n.mp3")mixer.music.play()

指定频道即可降低音量
import pygame

from pygame import mixer
mixer.init()
mixer.music.load("n.mp3")
pygame.mixer.Channel(0).play(pygame.mixer.Sound("n.mp3"), (-1))
pygame.mixer.music.set_volume(0.1)

您可以使用 set_volume() method of the pygame.mixer.Channel 对象设置频道的音量:

Set the volume (loudness) of a playing sound. When a channel starts to play its volume value is reset. This only affects the current sound. The value argument is between 0.0 and 1.0.

例如:

sound = pygame.mixer.Sound("n.mp3")
channel = pygame.mixer.Channel(0)
channel.play(sound, -1)
channel.set_volume(0.1)

决定了!

import pygame

from pygame import mixer
mixer.init()
mixer.music.load("n.mp3")
pygame.mixer.Channel(0).play(pygame.mixer.Sound("n.mp3"), (-1))
pygame.mixer.Channel(0).set_volume(0.3)