2017-12-21 4 views
1

두 개의 다른 채널에서 서로 다른 두 개의 오디오 파일을 지정하고 동시에 재생하는 코드가 있지만 각 채널을 하나의 채널에서만 재생할 수있는 방법이 필요합니다. 다른 채널의 다른 채널 예를 들어 두 개의 별도 오디오 파일 (Right and Left)에서 동시에 재생되는 두 개의 오디오 파일. 따라서 오디오는 오른쪽 스피커에서 재생되고 다른 오디오는 왼쪽 스피커에서 재생됩니다.왼쪽 채널과 오른쪽 채널에서 파이 게임을 사용하는 두 개의 서로 다른 오디오 파일 재생

아래 코드로 시도했지만 오디오가 특정 채널에 매핑되어 있지 않지만 두 스피커에서 재생 중입니다.

pygame.mixer.init(frequency=44000, size=-16,channels=2, buffer=4096) 
#pygame.mixer.set_num_channels(2) 
m = pygame.mixer.Sound('tone.wav') 
n = pygame.mixer.Sound('sound.wav') 
pygame.mixer.Channel(1).play(m,-1) 
pygame.mixer.Channel(2).play(n,-1) 

도움을 주시면 감사하겠습니다.

+0

채널의 색인이 생성되지 않았습니까? '채널 (0)'과'채널 (1)'이 필요할 수도 있습니다. – alxwrd

+0

나는 이해하지 못 했니? –

+0

pygame.mixer.Channel (0) .play (m, -1) pygame.mixer.Channel (1) .play (n, -1) 같은 결과를 가져 왔습니다. –

답변

1

왼쪽 스피커와 오른쪽 스피커의 볼륨을 Channel.set_volume으로 전달해야한다고합니다. 당신이 채널을 직접 관리하지 않는 경우


# Create Sound and Channel instances. 
sound0 = pg.mixer.Sound('my_sound.wav') 
channel0 = pg.mixer.Channel(0) 

# Play the sound (that will reset the volume to the default). 
channel0.play(sound0) 
# Now change the volume of the specific speakers. 
# The first argument is the volume of the left speaker and 
# the second argument is the volume of the right speaker. 
channel0.set_volume(1.0, 0.0) 

또한, 당신은 Sound.play() 반환하는 채널을 사용할 수 있습니다.

channel = sound0.play() 
channel.set_volume(1.0, 0.0) 
관련 문제