I have a 1hr video I would like to chop up into segments. I have been through the 1hr video, and have ~40 segments I want to chop and output into audio only (mp3) files, each file with a name. I have the start time, end time, and title all saved in a csv.
I'm aware of the python bindings (https://wiki.videolan.org/Python_bindings) and the documentation (https://www.olivieraubert.net/vlc/python-ctypes/doc/), but it's quite large, and I can't find what I'm looking for (VLC Media Player > Convert/Save).
Essentially I want to use the VLC ython API to provide a list of times (from/to), along with titles for each, so the API with use VLC to output into single mp3 files in a folder.
Anyone have any ideas where I can start, and what functions I should start with?
In typing this out a thought has occurred to me that there may be a python package that can do this (and avoid the need to use VLC), if so I'd be happy to hear about it also. Thanks,
Related
To save a lot of work, I'm trying to generate a sound file of a script for a play that includes several different voices. These voices should be computer generated. I have software (NaturalReader13) for generating these voices. Since I don't want the entire play read in one voice, I can't upload the whole text into NaturalReader and export it.
I could export several voice files and then mix them into a coherent whole, but this takes a long time and patience. I tried this already using Audacity to mix. Instead, I want to automate this by interfacing with the program using Python. I have no idea how to do this.
There are free voice generators online that would work for this task, but they are much lower quality. If interfacing with NaturalReaders is too complex, getting the data from the web might be easier.
So basically, the script I have is of the form:
Character: These are the lines that need to be read...
Any ideas on how to approach this?
I use Windows 7. All I want to do is create raw audio and stream it to a speaker. After that, I want to create classes that can generate sine progressions (basically, a tone that slowly gets more and more shrill). After that, I want to put my raw audio into audio codecs and containers like .WAV and .MP3 without going insane. How might I be able to achieve this in Python without using dependencies that don't come with a standard install?
I looked up a great deal of files, descriptions, and related questions from here and all over the internet. I read about PCM and ADPCM, as well as A/D Converters. Where I get lost is somewhere between the ratio of byte input --> Kbps output, and all that stuff.
Really, all I want is for somebody to please be able to point me in the right direction to learn the audio formats precisely, and how to use them in Python (but first I want to start with raw audio).
This questions really has 2 parts:
How do I generate audio signals
How do I play audio signals through the speakers.
I wrote a simple wrapper around the python std lib's wave module, called pydub, which you can look at (on github) as a point of reference for how to manipulate raw audio data.
I generally just export the audio data to a file and then play it using VLC player. IMHO there's no reason to write a bunch of code to playback audio unless you're making a synthesizer or a game or some other realtime app.
Anyway, I hope that helps you get started :)
I would like to do basic audio mixing in python.
To give an example: I would like to take two mp3 files and add them together and return one mp3 file. Another example: I would like to take the first ten seconds of one mp3 file and add it to the beginning of another mp3 file.
What is the best way to accomplish these tasks? I would like to use built in python functions like audioop but can not find any good tutorials or sample code out there for using the built in functions.
I am going through the docs but I am pretty confused and cannot figure out how to do things like this. I am not even sure that the python libraries like mp3's. Most of the stuff I have looked at seem to refer to WAV files. So, if this is the case, I guess a follow up question would be is there an easy way to convert an mp3 to a WAV for manipulation and back again?
You can do this pretty easily using pydub:
from pydub import AudioSegment
sound1 = AudioSegment.from_mp3("/path/to/file1.mp3")
sound2 = AudioSegment.from_mp3("/path/to/file1.mp3")
# mix sound2 with sound1, starting at 5000ms into sound1)
output = sound1.overlay(sound2, position=5000)
# save the result
output.export("mixed_sounds.mp3", format="mp3")
You could check out some of the code in the python audiotools project. It is a collection of command-line utilities which make use of a common python package. There is a utility included with audiotools (trackcat) which can con*cat*enate two or more audio tracks; another (tracksplit) can split an audio track (using a .cue file). These, as well as the numerous other included utilities, can work with audio files of various encodings, including mp3.
The way I've done this in the past is just use subprocess. and call sox.
E.g. subprocess.call(["sox", "in.1.mp3", "in.2.mp3", "out.mp3"])
Given a wmv file that is streaming online. The file is around 10kb as it does not have any video. If i click on the file it opens windows media player which then connects to the net. Windows media player starts to cache the file and then play the video for me.
Instead I would like my python program to open the file. Grab the content from the net and then download it for me. How would can I do this?
I was facing the same issue and looked into the Python VLC bindings but because I was pressed for time and there was a lack of examples using the bindings, I went for another approach.
The vlc command line is extremely powerful. Using subprocess.call i did direct calls to the vlc command line.
This is the format I used and it worked beautifully.
subprocess.call([path_to_vlc,
mms_url,
'--sout',
'file/avi:'+target_file,
'vlc://quit'])
In the part of the list of parameters you send to call, here is a description of each:
path_to_vlc -- As the name suggests. You don't have to use " to encapsulate spaces as with os.system for Program Files, etc. subprocess.call does that for you.
mms_url -- is the url to the stream. Since in my case it was a mms stream the param name stuck. You can use any of the supported vlc stream prefixes.
'--sout' -- since call encapsulate spaces for you, you need to explicitly separate each param where a space is needed. The actual param here is --sout file/avi:.... but we have to split them into two.
'file/avi:'+target_file -- The uri (and muxer) pointing to the target file. I used no path to the file since I was standing in the target directory when calling the python script. The target file should
'vlc://quit' -- Last we tell vlc to quit after playback. This way you get rid of the zombie vlc windows that stick around after.
If you wish to see the full code i used to first find the it here.
You could use the VLC Python bindings to handle the actual downloading and saving.
You'll need to get vlc.py from their Git repo.
Look at Instance.media_new_location.
I am looking for a high level audio library that supports crossfading for python (and that works in linux). In fact crossfading a song and saving it is about the only thing I need.
I tried pyechonest but I find it really slow. Working with multiple songs at the same time is hard on memory too (I tried to crossfade about 10 songs in one, but I got out of memory errors and my script was using 1.4Gb of memory). So now I'm looking for something else that works with python.
I have no idea if there exists anything like that, if not, are there good command line tools for this, I could write a wrapper for the tool.
A list of Python sound libraries.
Play a Sound with Python
PyGame or Snack would work, but for this, I'd use something like audioop.
— basic first steps here : merge background audio file
A scriptable solution using external tools AviSynth and avs2wav or WAVI:
Create an AviSynth script file:
test.avs
v=ColorBars()
a1=WAVSource("audio1.wav").FadeOut(50)
a2=WAVSource("audio2.wav").Reverse.FadeOut(50).Reverse
AudioDub(v,a1+a2)
Script fades out on audio1 stores that in a1 then fades in on audio2 and stores that in a2.
a1 & a2 are concatenated and then dubbed with a Colorbar screen pattern to make a video.
You can't just work with audio alone - a valid video must be generated.
I kept the script as simple as possible for demonstration purposes. Google for more details on audio processing via AviSynth.
Now using avs2wav (or WAVI) you can render the audio:
avs2wav.exe test.avs combined.wav
or
wavi.exe test.avs combined.wav
Good luck!
Some references:
How to edit with Avisynth
AviSynth filters reference