how to extract and convert audio file formats

This is an All-In-One Code Framework (http://1code.codeplex.com) sample to be published as KB. The sample package and the KBdraft are attached. The samples in the project are featured by:
 
1) Sample Source: The samples are refined out of CSS developer supports forcustomers. You can think of the samples as a collection of most frequentlyasked coding scenarios in contrast with FAQs.
2) Three Languages: Almost all samples are provided in three popularprogramming languages: VC# and VB.NET when applicable.
3) All-In-One: All sample for all Microsoft development techniques are in onesolution.
4) Simple build and run experience.

 

How to extract and convertaudio file formats

This article describes anAll-In-One Code Framework sample that is available for download. The sample demonstrates how to extract and convert audiofile formats, which include wav, mp3 and mp4 files.

 

The sample is used to extractmusic file formats. We usually play music with Windows Media Player or othermusic-playing software. If we find our favorite music clip, we can use thefunction of this sample to extract it and convert it into another file format.All technology mentioned above is based on Expression Encoder SDK 4.0. When youinstall Expression Encoder 4.0, you can use Visual Studio 2010 to add areference to it. In this way, you don't have to install the SDK installationkits individually.

 

The sample uses ExpressionEncoder SDK 4 to output *.mp4 or *.wma file. The .mp3 audio format is currentlynot supported as output format in Expression Encoder 4.

Difficulty Level

Medium

Technicaloverview

 

1.        Usefollowing helper function to cut the audio file from startpoint to endpoint,and output the clip as the selected audio format. 

 

public static string ExtractAudio(string sourceAudioFile, string outputDirectory,

        OutputAudioType outputAudioType, double startpoint, double endpoint)

    {

        using (Job job = new Job())

        {

            MediaItem src = new MediaItem(sourceAudioFile);

            switch (outputAudioType)

            {

                case OutputAudioType.MP4:

                    src.OutputFormat = new MP4OutputFormat();

                    src.OutputFormat.AudioProfile = new AacAudioProfile();

                    src.OutputFormat.AudioProfile.Codec = AudioCodec.AAC;

                    src.OutputFormat.AudioProfile.BitsPerSample = 24;

                    break;

                case OutputAudioType.WMA:

                    src.OutputFormat = new WindowsMediaOutputFormat();

                    src.OutputFormat.AudioProfile = new WmaAudioProfile();

                    src.OutputFormat.AudioProfile.Bitrate = new VariableConstrainedBitrate(128, 192);

                    src.OutputFormat.AudioProfile.Codec = AudioCodec.WmaProfessional;

                    src.OutputFormat.AudioProfile.BitsPerSample = 24;

                    break;

            }

 

            TimeSpan spanStart = TimeSpan.FromMilliseconds(startpoint);

            src.Sources[0].Clips[0].StartTime = spanStart;

            TimeSpan spanEnd = TimeSpan.FromMilliseconds(endpoint);

            src.Sources[0].Clips[0].EndTime = spanEnd;

 

            job.MediaItems.Add(src);

            job.OutputDirectory = outputDirectory;

            job.Encode();

 

            return job.MediaItems[0].ActualOutputFileFullPath;

        }

    }

 

2.        Use the Windows Media Player control to play thesource audio file. The following MSDN article introduces how to embed theWindows Media Player ActiveX control in a Windows Form. http://msdn.microsoft.com/en-us/library/dd562851.aspx

 

For more information about how to create and deploy thesample application, see the Readme.txt file that is included in the downloadpackage.

Technologycategory

Network

Languages

 
 

Language

 
 
 

Project Name

 
 
 

Visual C#

 
 
 

CSExtractAudioFile

 
 
 

Visual Basic.NET

 
 
 

VBExtractAudioFile

 

 

Prerequisites

Thissample application was created by using Visual Studio 2010, .NETFramework 4 and Microsoft Expression Encoder 4.

References

 

Expression Encoder SDKProgramming Reference

http://msdn.microsoft.com/en-us/library/ff396833(v=Expression.40).aspx

 

 

Microsoft Expression Encoder 4FAQ

http://social.expression.microsoft.com/Forums/en/encoder/thread/3eabf903-b49f-4f92-b508-f28a795d6c90

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值