Can't get winsound.Beep to work - python

I am trying to make some Beep noises with the winsound.Beep command. However when I am using winsound.Beep(500, 500) I do not hear anything. With winsound.MessageBeep and winsound.PlaySound however, I DO get to play sounds. Any ideas what I should do?
What I am trying to do: I want to write a little practicing program for training intervals: the computer sounds a first tone, then a second tone and you will have to guess what the tone interval is. For this I need pitched tones, tones for which I can set the frequency. I want to keep it as simple as possible, any pitched sound will do. I do not want to have to collect a set of .wav files or whatever. I want to make use of a tone generator which I think is available on most soundcards. winsound.Beep seems like something that can do this trick, but any other suggestions are welcome.

I had the exact same problem. winsound.Beep used to work just fine and then it suddenly stopped working (or that's what I thought). The problem was that someone (or some update) had turned off the System sounds, which prevented windows from playing the Beep sound, either manually or through my program. Try right clicking on the Speaker symbol, Open volume mixer and check whether System sounds is off or minimum volume.
I hope that helps!

Are you sure that your computer has a beep? A lot of recent computer remove the beep because it was annoying and most computer today have soundcard to play wav sound instead (the other sound that you are able to play).
You can also check to validate if it's activated on this page
IMO, I think that using the beep for other things than debugging is not a good idea.
EDIT
Mayby you can try this code to create a sound using a base wav with synth algorythm

Related

winsound.PlaySound() not working properly

Recently I tried to implement a "Beep" sound to my code, I tried it with winsound.Beep(), but I have the beep disabled on my computer. Then i tried it with winsound.PlaySound('Test.wav', winsound.SND_FILENAME ), but when I run the code I only hear the windows background sound and not the actual sound.
winsound.PlaySound() is always going to play something, unless you explicitly add the SND_NODEFAULT flag. Your Test.wav file apparently doesn't exist in the current directory, or isn't in a format that Windows can read, so you're getting a default sound instead.

How to use streaming with pygame.mixer [duplicate]

I am trying to make my own music player with Python, and after looking at alternatives, I've settled on using pygame's mixer.music to actually play the audio. (I've used pygame before, just usually for actual games) I was looking at playsound instead until I realized I needed a way to play the next song once one is done, as well as the ability to play and pause the audio. I also need to play mp3 files instead of the wavs that most alternatives require.
I actually got it working perfectly originally, until I tried adding other unrelated features, and now it's saying:
File "main.py", line 66, in playCurrentSong
mixer.load(path.join(museDir, currentSong))
pygame.error: Error reading the stream. (code 18)
(museDir is my variable for the directory that music files are in, and mixer is my variable for pygame.mixer.music as a shorthand)
I cannot figure out for the life of me why it's giving me this error now, as it played the audio perfectly fine before. My code is here: https://pastebin.com/V7nAfmK6
If a solution only works on a certain operating system, my final OS will be Linux, on a Rasperry Pi, but I'm trying to write and test the code on Windows. However, if that's not possible, I understand.
Thank you beforehand for any and all help; this is giving me a headache.
I just found the source of the problem.
Before the error popped up, I had been trying to mess around with the metadata of the mp3 files in order to incorporate a genre system into the player, but nothing was working. I eventually decided to use csv files for that instead.
I must have done something wrong however when I was messing around with that metadata because I looked at the mp3s in File Explorer, and they were all 0 bytes. That's why pygame couldn't read the stream: there wasn't one! I plugged the pygame stuff back in, replaced the mp3s with new ones, and it works just fine now.
Thanks for the help anyway though, Torxed!

Is it possible to ensure audio isn't modified when playing back under Windows

We have a python program which outputs specific waveforms over the audio to drive an LED, for an easy and cheap robot programming device.
With the windows systems that we've tested everything works fine, but on some systems the waveform seems to be altered. We've used the control panel to disable any 'enhancements' for the audio output endpoint but it doesn't seem to help.
So, is it possible, using python, to instruct Windows to play audio unchanged? Or do some of the audio gurus here have another theory of what could be affecting the audio?
Sound cards are for playing audio, not sending data. You can't rely on an arbitrary signal not being altered by the hardware, much less the software. For example, many sound cards have a capacitor in series with the output to filter out DC bias. If you try to pass a DC-biased (or very low frequency) signal through such a sound card, it will be distorted. And there's nothing you can do about it at the software level.

Play do-re-mi musical notes (each lasting 1 sec) on Python

My son plays a string instrument that sounds terribly out of tune. I would prefer him to learn some simple Python programming to play do-re-mi notes that really sound like do-re-mi.
As a start, I would like to play do-re-mi with each note lasting 1 second duration on Python. Can this be easily done on Python? Easy means the code can be explained to a 10-year-old kid or at least not so difficult that he is put off.
I am using Python 2.7 on Windows 7.
Sounds like you are trying to program a synthesizer using python... Not a simple task. However if you do not require any smooth transition from one note to the next, and no tempo change etc. i.e. just have the program recite the notes in "Close Contact of 3rd kind" fashion, I guess you could store the digital notes in regular sound files. Have an array of these filenames, in what order you want to play them, then just issue the command to play the notes one at a time with a wait in between. There are a number of python sound libraries: Snack sound, pyMedia, pyglet, winsound (build-in to the windows python), pygame, wxPython (probably a lot more)
I like the simplicity of pygame:
import pygame
import time
notes = ['note1.mp3', 'note2.mp3', 'note3.mp3', 'note4.mp3']
pygame.init()
for note in notes:
pygame.mixer.music.load(note)
pygame.mixer.music.play()
time.sleep(2)
Here it might take a little bit to learn but try PyAudio. You may have to def some functions to generate the sound waves (represented by strings). Other options include winsound, Nsound, sunau, etc it depends how you want to play the sound.

Detect when computer becomes active?

I am having trouble finding an answer of how I could do this.
Basically what I want is to have a program start automatically when it detects that I am using the computer. So for example say I stop using the computer for a few hours and then come back, it would detect this and then open another program or something.
I am looking for a solution in Ruby/python/objective c/Applescript preferably. But anything would work.
I'd like it to work on Snow Leopard.
Any suggestions would be great!
You can monitor all events in the system using NSEvent addGlobalMonitor.... Keep track of the time between two successive events, if it's over a treshold, it means the user was inactive for that time.

Categories

Resources