I am learning python. I thought of a fun and do-able(for me as a noob) exercise to test myself with.
I want to write a script that asks the user for a string.. and then it translates the string into morse code and plays it. I just dont know how to access/play a sound file in Python... Doesnt really matter what type.. .wav .mp3 or whatever, just whatever works best with Python. It obviously will just be a short beep that will be played for a certain(very short) time length. I saw that people suggest using pygame.. is that the only option? For educational purposes I'd like to know how to do this with the standard library(if possible). If not a module is fine.
Or better yet, is there a way to create a beep sound with only python code? In other words no sound file needed at all. A function that says "make a sound at x frequency for x time"?
You could try the winsound library (built in).
By using winsound.PlaySound(filename,winsound.SND_FILENAME) you are able to play WAV audio files.
By using winsound.Beep(frequency(in Hz),duration(in miliseconds)) you should be able to produce a beeping sound.
There is a slight chance the Beep() function won't work, as is in my case, and i am currently looking into it.
Take a look at the docs here: https://docs.python.org/3.7/library/winsound.html
Related
I want to write a program in Python which plays random music. Is there any library that can directly play a sound of the given pitch or frequency, during the given time? For example, play(440, 4) should play the note A during 4 seconds.
I've found some libraries that can do what I said, but they don't play the music directly: you have to create a .wav file and, then, play this file. If I don't find any library that does what I want, I'll create a file, play it, and remove it for each note, but I think it would be more easy to do it directly.
I've finally found an answer to my question.
There's a module called winsound (https://docs.python.org/3/library/winsound.html) which can play a sound of a given frequency and duration: winsound.Beep(frequency, duration). But the problem is that it isn't cross-platform, only works for Windows operating systems.
So I've found another module called pyaudiere (https://pypi.org/project/pyaudiere/) which is cross-platform. It works a bit different than winsound. First you create a device: d = audiere.open_device(). Then, you can create a tone doing t = d.create_tone(440). To play the tone you do t.play() and to stop it t.stop(). If you want to play it during some seconds you can use the time module. I'm still investigating but I think it only works for Python2. This is the stackoverflow post where I found the answer: Python library for playing fixed-frequency sound.
I'm trying to write something that catches the audio being played to the speakers/headphones/soundcard and see whether it is playing and what the longest silence is. This is to test an application that is being executed and to see if it stops playing audio after a certain point, as such i don't actually need to really know what the audio itself is, just whether or not there is audio playing.
I need this to be fully programmatic (so not requiring the use of GUI tools or the like, to set up an environment). I know applications like projectM do this, I just can't for the life of me find anything anywhere that denotes how.
An audio level meter would also work for this, as would ossiliscope data or the like, really would take any recommendation.
Here is a very similar question: record output sound in python
You could try to route your output to a new device with jack and record this with portaudio. There are Python Bindings for portaudio called pyaudio and for jack called PyJack. I have never used the latter one but pyaudio works great.
Is it possible to get the system output audio (the exact same thing that goes through the speakers) and analyze it in real time with Python? My intention is to build a sound visualizer. I know that it is possible to access the microphone with pyaudio, but I was not able to access the sound card output in any way, I'm looking for a solution that works on Windows.
Thank you for reading.
Not sure how this project is doing these days, it's been a long time since it's been updated. PyVST allows you to run python code in a VST inside a VST host, which makes it possible to handle realtime audio events.
You might want to look at http://code.google.com/p/pyo/ for some ideas about how to handle DSP data as well.
I am searching for a way to write a simple python
program to perform an automatic edit on an audio file.
I wrote with PIL automatic picture resizing to a predefined size.
I would like to write the same for automatic file re-encoding into a predefined bitrate.
similarly, i would like to write a python program that can stretch an audio file and re-encode it.
do i have to parse MP3's by myself, or is there a library that can be used for this?
Rather than doing this natively in Python, I strongly recommend leaving the heavy lifting up to FFMPEG, by executing it from your script.
It can chop, encode, and decode just about anything you throw at it. You can find a list of common parameters here: http://howto-pages.org/ffmpeg/
This way, you can leave your Python program to figure out the logic of what you want to cut and where, and not spend a decade writing code to deal with all of the audio formats available.
If you don't like the idea of directly executing it, there is also a Python wrapper available for FFMPEG.
There is pydub. It's an easy to use library.
I need a python library or module or whatever that can compare a .wav file to microphone input without too too much code. Sample code would be cool too. TY!
I don't know if there's a library already for that, but if you have the microphone input as a WAV file as well, you can use the wave and audioop modules and write it yourself.
If you're trying to compare something like, what words people are saying, this would have to be a fairly complex piece of code. You could directly compare them at a frequency/wave level, but you'll very rarely if ever get a match.