Why does pygame.mixer.Sound only produce a popping sound before abruptly stopping?

My attempt to play sound using Python through pygame is resulting in a strange issue. When I run the program, all I hear is a popping noise and then it abruptly quits. The audio track I am trying to play is at least 20 seconds long, but for some reason the program crashes right after the pop sound.

I've experimented with alternative solutions instead of pygame, but the popping noise persists with those as well. It appears to be a problem specific to my machine (Mac) but I can't figure out why it's behaving this way.

import pygame
pygame.init()
pygame.mixer.init()
sound = pygame.mixer.Sound("SampleAudio_0.4mb.wav")
sound.play()
while pygame.mixer.get_busy():
    pygame.time.delay(1000000)

Answer №1

I saved a WAV file from the following link:

After that, I executed the following Python code:

import pygame
pygame.init()
pygame.mixer.init()
sound = pygame.mixer.Sound("thunder2.wav")
sound.play()
print(pygame.mixer.get_busy())
while pygame.mixer.get_busy():
    print(pygame.mixer.get_busy())
    pygame.time.delay(1000)
print(pygame.mixer.get_busy())

The output was as follows:

pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
1
1
1
1
1
1
1
1
1
1
1
0

Did this code work correctly for you? In my case, the '1's (indicating that get_busy is returning true) were continuously printed while the sound was playing. Once the sound finished and the delay elapsed, the program closed.

Is this the expected behavior for you as well?

Note: I am using Python version 3.7.1.

If you encounter a different outcome when running this code on your machine, please share the details so we can identify any potential issues.

If you have a publicly available sound file that you'd like me to test with, kindly provide the link so I can run the program with that file as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking for ideas on how to use Python and Selenium for web scraping?

Input Field: <input type="text" auto_complete_item_format="<b xmlns=&quot;none&quot;>[_full_name]</b>" auto_complete_display_field="_full_name" auto_complete_id_field="suburb_id" auto_complete_ ...

Navigating a list and deleting items by their index in Python

Currently, I am facing the task of handling a CSV file where I need to search through each element for a match with a regular expression. If a match is found, my goal is to remove that specific element. However, I specifically want to remove the element by ...

When working in Flask, I am experiencing an issue where my CSS is not linking to my

I am new to coding with HTML, CSS, and Flask and I have encountered an issue where my CSS styling only partially affects my HTML file. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...

Live Plot of Data in Matplotlib - Time Series Visualization with Time on the x-axis

Is it possible to use time as x-axis values for a live matplotlib graph? If so, how should it be implemented? Despite trying various methods, I keep encountering errors. Below is my current code: update_label(label): def getvoltage(): f=ope ...

How come this Python script fails to detect the numerical value within a string?

I'm facing a challenge with extracting numbers from a string that includes commas. If the comma is removed, the function works fine; however, when it's left in place, the function malfunctions. It's puzzling why the presence of a comma poses ...

Using Python variables within an IF statement

After searching for a solution, I realized that none of the methods I tried matched my specific issue. Currently, I am utilizing fabric with a run command to execute hostname -i remotely. Here is the snippet of code: ip = run("hostname -i") if %s in run(" ...

Error Encountered while Implementing Image Classification Model using Tensorflow/Keras

My partner and I are collaborating on a project to create a model that can classify images based on whether or not they show someone wearing a mask correctly. However, we're encountering an issue when trying to run our model - a ValueError keeps appea ...

Generate a new column in pandas by extracting the ending characters of strings with varying lengths

Dataframe description total average number 0 NFL football (white) L 49693 66 1007 1 NFL football (white) XL 79682 74 1198 2 NFL football (white) XS 84943 81 3792 3 NFL football (wh ...

Preventing Selenium from immediately exiting and addressing issues with keys not being typed

Is anyone else experiencing the issue where the site opens for a split second and exits, and it doesn't type what it's supposed to? How can this be fixed? I've tried multiple methods to locate the element, and I believe my approach is corre ...

The soft time limit for celery was not activated

I am facing an issue with a celery task where the soft limit is set at 10 and the hard limit at 32: from celery.exceptions import SoftTimeLimitExceeded from scrapy.crawler import CrawlerProcess from scrapy.utils.project import get_project_settings @app.ta ...

Python: Implementing data validation with regular expressions

Trying to utilize Python regular expressions for validating a variable's value. The validation criteria are: The value may consist of any combination of a-z, A-Z, 0-9, and * (no spaces, dashes, commas) The value can begin with a number (0-9), lette ...

Forecasting with a combination of various input variables in a time series analysis

Imagine we are working with a time-series dataset that shows the daily count of orders over the past two years: https://i.stack.imgur.com/vI2AA.png To predict future orders, Python's statsmodels library can be used: fit = statsmodels.api.tsa.statesp ...

What is the best way to verify if a character falls within the range of A-Z and a-z in Python?

Requirements for the word include at least two uppercase A-Z characters and one lowercase a-z character. To check for lowercase characters, I used the .isalpha() function. How can I do this with uppercase characters as well? Currently, my solution involve ...

Combining Data Tables from Multiple Pages Effortlessly with Python

In the process of developing a program, I am focusing on analyzing smaller companies and gathering data on insider buying. The current script is designed to collect data from every company in a comprehensive table ('http://openinsider.com/latest-penny ...

Attempting to navigate through profile directories with Selenium

I'm currently working on a project where I need to loop through all profiles and extract the name of the person, their job profile, and location. Below is the screenshot of the LinkedIn screen I am referencing: https://i.stack.imgur.com/s3bUV.png He ...

Failure to upload file using AngularJS

Below is the code snippet for file uploading: Here is the HTML code used to select and upload the file: <form ng-click="addImportFile()" enctype="multipart/form-data"> <label for="importfile">Import Time Events File:</label><br&g ...

Automatically installing packages in Python

Currently, I am encountering an issue with Python. After creating my script, I downloaded a library and installed it on my Ubuntu system to use in the script. However, when giving the script to a client or another user, they may not know which libraries ar ...

Trace function manually in Pyodide without causing main thread to be blocked

I'm currently working on developing a browser-based debugging tool for Python, but I'm encountering difficulties in merging the inner workings of Python with user interactions. You can see my setup in action at this link on jsfiddle. Essentially, ...

What steps are involved in organizing data sets from a series of values?

Below is a list that I've created, data = (i for i in list("abcdefghijklmnopqrstuvwxyzabcedefghijklmnopqrstuvwxyz")) The variable data is a generator containing data points. My goal is to group these datapoints into batches of 12, with the ...

Discovering the xpath with a certain condition based on text length using Python Selenium

In my quest to extract the specific content I need from countless pages, I have devised a reliable rule that works 99% of the time: //a[@class='popular class' and not (contains(text(),'text1')) and not (contains(text(),'text2&apos ...