Raspberry pi not giving audio output

Viewed 156

I want to play an audio file on my raspberry pi. So far I have used PyAudio, PyDub and Pygame but none of theme work. I also used omxplayer to play the audio file and the speaker worked which means that raspberry pi is able to detect the speaker attached. So I don't understand what's the problem with code since it doesn't even throw any errors.

For pygame:

from pygame import mixer
import time
mixer.init()


mixer.music.load('Applause/previewand the winner is.mp3')
mixer.music.play()
time.sleep(2)
mixer.music.stop()

For pydub

from pydub import AudioSegment
from pydub.playback import play
from pydub import effects

music = AudioSegment.from_mp3('<File>')
play(music)

Python version : 3.7.3

1 Answers
import pygame
from pygame.locals import*
pygame.init()
pygame.mixer.music.load("file_name.mp3")

pygame.mixer.music.play(0,0.0) #The parameters are the loops and the time the audio should start from.

This worked for me.

Related