I'm working on a python3 project (in PyCharm, using Windows 10) and I'm trying to play a series of tones and save them all to a mp3 file.
I can get it to play a series of notes with winsound:
import winsound
while True:
winsound.Beep(1000, 1000)
But I can't save it.
All help appreciated!
If you want to save output to a file, rather than just play it, probably the most ideal way of doing this is to generate midi files. There are a few packages that can help you create midi files in a similar way.
This example uses the package called mido
from mido import Message, MidiFile, MidiTrack
mid = MidiFile()
track = MidiTrack()
mid.tracks.append(track)
track.append(Message('note_on', note=64, velocity=64, time=32))
mid.save('new_song.mid')
You can convert midi files to MP3s easily if needed (many programs or even online tools can do this) although, midi files are generally well-supported in most applications.
See also
Although perhaps dated, you can also check the PythonInMusic wiki for references to more MIDI and other audio libraries.
Alternatively, you can use a separate program to record your audio output when running your python script using winsound.
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 am creating a neural network that produces musical instrument like sounds on a server that then pulls that data to iOS application. Therefore, the process must be automated. (More on that later.)
Here is the strange thing though when listening to the audio using ipd.audio sounds perfectly fine on download and in the notebook. But using any other library it causes it to sound horrid.
What libraries I have tried so far:
Scipy
Liborsa
Soundfile
If I can just programmatically call ipd.audio to write the wav file to a specific location then I will be set.
Code Snippet:
(Please be careful when listening to the files in the zip file. Lower your audio please I don't want to hurt anyone ears...)
Link to the audio files: https://drive.google.com/open?id=10AaDi_ITOCQv2hsxd9_UDV2OYLWd1_Da
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 using Python, and I want to analyze audio files from internet streaming media (for example Youtube, Soundcloud, etc.)
Is there a universal way to do so? There is a pre-loading for every music or video, there must be a way to access it? How?
I want to run this script on an external server, that might be relevant to the answer.
Thanks
All sound you "hear" on your pc has to run through your soundcard, Maybe somehow write a script that "records" the sounds runnning through the device. Maybe u can use Pymedia module?
I'm looking for a cat for aac music files (the stuff iTunes uses).
Use Case: My father in law will not touch computers except for audiobooks he downloads to his iPod. I have taught him some iTunes (Windows) basics, but his library is a mess. It turns out, that iTunes is optimized for listening to podcasts and random songs from your library, not for audiobooks.
I would like to write a script (preferably python, but comfortable with other stuff too) to import his audiobook cds in a sane fashion, combining the tracks of each cd into a bookmarkable aac file (.m4b?) and then adding that to iTunes so it shows up in the audiobooks section.
I have figured out how to talk to iTunes (there is a COM interface in Windows, look for the iTunes SDK). Using that interface, I can use iTunes to rip the CD to aac format. It's the actual concatenation of the aac files I'm having trouble with. Can't find the right stuff on the net...
I created a freeware program called "Chapter and Verse" to concatenate m4a (AAC) files into a single m4b audiobook file with chapter marks and metadata.
If you have already ripped the CD's to AAC using itunes (which you say you have) then the rest is easy with my software. I wrote it for this exact reason and scenario. You can download it from www.lodensoftware.com
After trying to work with SlideShow Assembler, the QT SDK and a bunch of other command line tools, I ended up building my own application based on the publicly available MP4v2 library. The concatenating of files and adding of chapters is done using the MP4v2 library.
There are quite a few nuances in building an audiobook properly formatted for the iPod. The information is hard to find. Working with Apple documentation and open libraries has its own challenges as well.
Best of Luck.
Not programming related (well, kinda.)
iTunes already has functionality to rip as a single track (e.g. an audiobook.) Check this out: http://www.ehow.com/how_2108906_merge-cd-single-track-itunes.html
That fixes your immediate problem, but I guess people can keep discussing how to do it programatically.
The most powerful Python audio manipulation module out there seems to be Python Audio Tools. The download comes with CLI tools that would probably do everything you'd want to do, even ripping, so you can even get by with shell scripting the whole thing. The module itself is also pretty powerful and has a handy set of functions to manipulate audio files. If you want to stick with writing everything in python, you can possibly learn enough to do what you want to do after studying their CLI source code. Specifically they have a tool that just does audio file cat in any codec. (They do depend on FAAC/FAAD2 for AAC support, but that'd be true for every library you'll find)
I haven't seen an aac codec library for python, but you could use wav files as an intermediary format.
You can pull the tracks off the cd as wav files, and then use the wave module to concatenate them into one large file, which could then be converted by itunes to aac. This may increase your processing time considerably because of the size of the data, but it would be fairly easy, and you don't need any external libraries.