Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pygame play sound

import pygame

pygame.mixer.init()
crash_sound = pygame.mixer.Sound("crash.wav")
crash_sound.play()
Comment

how to play audio in python using pygame

from pygame import mixer
  
# Starting the mixer
mixer.init()
  
# Loading the song
mixer.music.load("song.mp3")
  
# Setting the volume
mixer.music.set_volume(0.7)
  
# Start playing the song
mixer.music.play()
  
# infinite loop
while True:
      
    print("Press 'p' to pause, 'r' to resume")
    print("Press 'e' to exit the program")
    query = input("  ")
      
    if query == 'p':
  
        # Pausing the music
        mixer.music.pause()     
    elif query == 'r':
  
        # Resuming the music
        mixer.music.unpause()
    elif query == 'e':
  
        # Stop the mixer
        mixer.music.stop()
        break
Comment

PREVIOUS NEXT
Code Example
Python :: How to have add break for a few seconds in python 
Python :: sorting by column in pandas 
Python :: resize imshow opencv python 
Python :: clear outpur jupyter 
Python :: python actualizar pip 
Python :: tensorboard in colab 
Python :: check filed exist in object python 
Python :: How to play music without pygame 
Python :: pandas set options 
Python :: how to feature selection in python 
Python :: set recursion limit python 
Python :: python pandas change or replace value or cell name 
Python :: incognito mode in selenium 
Python :: cube finder python 
Python :: django previous url 
Python :: change specific column name pandas 
Python :: webhook discord files 
Python :: auto datetime in django models 
Python :: save plot as image python 
Python :: how to right click in pyautogui 
Python :: selenium refresh page python 
Python :: split string into array every n characters python 
Python :: long to_bytes python how to use it 
Python :: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(ChromeDriverManager().install()) 
Python :: auto clicker in python 
Python :: python 3 pm2 
Python :: pyspark import f 
Python :: numpy to csv 
Python :: how i install jupyter notebook in a new conda virtual environment 
Python :: python install command in linux 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =