How can I split an mp3 file into several individually playable parts? - c#

How can I break a large mp3 file into one or more mp3 files, and still have each part playable in a media player?

It's probably not going to be super easy to break an mp3 file into separate playable mp3 files. There is header information in the mp3 file that you will need to include in all of the split-up files. You might need to get a book or look for a file spec on mp3s, so you know what you're dealing with.
You might be best-off looking for a library that can deal with mp3 files, rather than trying to do it yourself with a FileStream.

Actually, breaking a MP3 file into seperate playable MP3 files is quite easy. A MP3 file consists of a lot of individual frames of iirc 1500bytes, where each has it's own header. Invalid data will be ignored by the player.
But, it would be a lot better if you where to split your files on frame boundaries, creating correct mp3 files. More info on the frame header can be found on this site: http://www.mp3-tech.org/programmer/frame_header.html
Please also consider the possibility that the music is prepended and/or appended with various meta tags, like ID3, APE and lyrics.

Related

Split the audio file by words

There is audio file. Where few "words" with different time between them. I need to make as many .wav files as "words" in the file. Audio file is very clear, there is no noise, so it must be very easy to find the "words". Any ideas how to make it with C#? Maybe somebody knows any libraries?
Please check an example of waveform of the file:
NAudio is good. You'll be able to read the WAV header so you know what format was used to store the file. Then you can just scan it and grab the regions where the entropy is higher.
https://naudio.codeplex.com/releases/view/612263

Rendering a wav file from wav files in c#

I got some short .wav files and after i get sequence how it should be played in time I need to "render" a one wav file which will contain that .wav files. I know I can append it but the problem is that some wav files should be played at one time, and also it need to be in rhythm (exact spaces).
How?
You will need to use some libraries like ffmpeg or SoX to do this.
Reference: http://ffmpeg.org, http://sox.sourceforge.net

How to get sound portion of an MP4 (video file)?

I am developing a windows phone 7 application and it does video recording. I would like to get the sound portion of the video file (MP4) and do some enhancements on the sound. I believe sound is saved as AAC frames in MP4. (Right?) How can I extract sound of a videa MP4 file?
Since this is a video file, it can be huge file. So uploading to cloud and processing there is not a good option. Since this WP7 application I cannot use unmaged dlls :( Is there a way to do in pure C#? Any open source tools/samples?
Thanks!
MP4 is a container format and realistically the sound portion isn't always AAC. It could be MP3 or any other number of different audio formats. You may be thinking of M4A, which I believe requires either AAC or ALAC.
On the subject of audio extraction, it should be possible to extract the audio from an MP4 using just managed code. You'll have to read up on the MP4 format (here, for example - this question is also worth reading) and then search through the file for the location of the audio and then either copy it to its own buffer or do your manipulations in chunks. Even then, you'll have to be able to recognize when it isn't an audio format that your app won't support.
It's possible that there already exists a .net library that can do all of this but I don't know of any. It's probably not very popular because managed code is definitely not the best angle to approach this from, but considering this is Windows Phone, it is, as you noted, your only avenue of approach.
Good luck!

C# manipulating video

i want to take a folder of pictures, and turn it into a slideshow video with music in the background.
i have no idea how to do this, or where to get help, cos this isnt the kind of thing you can search in google.
idk if there are api's for it, or if it can even be done in C#.
maybe ill have to move the project to C++ or something, but first i need to know where the hell to start.
thanks.
This is definitely the kind of thing you can search in Google. Try "creating avi files in C#" and pick one of the answers. I recommend this one from personal experience.
Creating an AVI file is actually pretty easy - you basically just set a frame rate and dump in a bunch of bitmap files, then add a WAV or MP3 file (or files) for the audio, and that's it.
The AVI file can then be played as is, or compressed into an MPEG or whatever (although you won't get much size compression with a slideshow-type video file, you also don't need it as much).

WAV file auto repeat in C#

I have a 10 second sound effect wave file. What I would like to do is take that file and repeat it n number of times and then save the longer WAV file to disk. This way I can create a much longer background effect rather than auto-repeat on the media player which is a bit stuttered between repeats. I am trying to do this in C#.
That's reasonably easy to do, given the WAV file format - assuming it's uncompressed audio (most WAV files are - or at least, they were last time I had anything to do with them).
There may well be audio APIs you can use to do this without getting stuck into the binary format, but I suspect they'd take as long to learn as just doing it yourself as you're not doing anything particularly complicated.
If you only need to do this with a small number of files, you might as well do it by hand with Audacity.
If you're using .Net 2.0 or higher then you can use the System.Media.SoundPlayer class and specifically its PlayLooping method to achieve what you want with no stuttering. This is preferable to creating a new wav file - it means less disk space for the file and less memory needed to render the sound. In general you should always use buffered techniques like this for audio playback if the sound will be looped or is longer than a few seconds.
You can do this easily in C# using the NAudio .NET audio library. You would need to use the WaveFileReader and WaveFileWriter classes. You can also use it to create a custom WaveStream that will loop your audio as many times as you want without the need to create a long WAV file.

Categories