asp.net audio conversion. Amr turn. mp3 Tutorial (using the Seven Cow conversion method)

Source: Internet
Author: User

Objective

I believe you all know it,. amr format for mobile device audio, compression compared to larger, more for the voice, call, the effect is OK! So, the mobile device uses AMR format to record and save more! A more common example: Call recording, micro-letter voice and recording, etc.!

But this ghost, in two words to describe, is "egg pain", because HTML5 does not support it (AMR: I am an orphan, Director: Zomi Chilla), so, the audition effect is very difficult to achieve! While the micro-letter is a trial, but once left the page, it means that you can no longer play your recording!

So you have to convert the file format!

At present, there are two ways to master the conversion format: one is to upload to seven cattle cloud services for conversion download, the second is through the FFmpeg application for conversion! This article first introduced the use of seven cattle conversion implementation method, let's take a look together.

Seven Cattle conversion method:

1. First, register seven Neu Yun storage!

2. Seven cattle will return to you the "two" pass, pass is the communication of seven cattle essential tools! A picture above:

AK and SK are the prerequisites for program execution!

3. Create space, add queues! Space name, and queue name are all used to!

Space is to store your uploaded files of the warehouse, the queue is processing documents factory! Can create multiple!

Space needs to configure the domain name!

4. Download the source code for seven cattle: I am the link

There's a file called "Qiniu.4.0.dll" in the file that references it to your project!

The code is as follows Copy Code
<summary>
Set up your AK, SK and domain names
</summary>
Privatestaticvoidsetkey ()
{
Set up an account of AK and SK
Config.access_key = "########################################";
Config.secret_key = "****************************************";
Config.api_host = "http://###.***.com";
}

5. Upload the file, and notify the seven cattle to the file conversion format, the following examples are:. AMR format turns. MP3 format.

The code is as follows Copy Code
<summary>
Upload file and pre-turn format
</summary>
<param name= "key" > FileName to convert format </param>
<param name= "FilePath" > File path </param>
<returns></returns>
Privatestringupload (Stringkey,stringfilepath)
{
Ioclient target =newioclient ();
Putextra extra =newputextra ();
Set the space name that is stored after the file is uploaded
String bucket = "amrtest";
Normal upload, only need to set the space name of the upload can be, the second parameter can be set token expiration time
Putpolicy put =newputpolicy (bucket, 3600);
The file after the transcoding is customized with the SaveAs parameter or unspecified, and the file is named by default and saved in the current space.
Stringmp3tpname = key. Split ('. ') [0]. ToString () + ". mp3";
String urlbase64 = Qiniu.Util.Base64URLSafe.Encode (bucket + ":" + mp3tpname);
Generally refers to the target storage space (Bucket) on which the file is to be uploaded. If it is "Bucket",
Indicates that the qualification can only be uploaded to the Bucket (new file only), and if "Bucket:key" indicates that a specific file is qualified, modify the file.
Put. Scope = bucket + ":" + key;
Optional. If not 0, even if the scope is Bucket:key form is insert only.
Put. insertonly = 0;
// "|" The vertical bar is the command you want to convert the format to; After the conversion is complete, the name of the file and the namespace of the storage space!
Put. Persistentops = "avthumb/mp3/ab/128k/ar/44100/acodec/libmp3lame|saveas/" + urlbase64;
Specify the document to be modified in that "factory", which is the name of the queue!
Put. Persistentpipeline = "Littlebai";
After the audio-video transcoding is persisted, the seven-cow server will send the user the processing result notification. The URL specified here is the interface used to receive notifications.
Set ' Persistentops ', you need to set this field at the same time
Put. Persistentnotifyurl = "http://***.###.com/***/default.aspx";
Generate Upload Token
Stringuptoken = Put. Token ();
Uploading files
Putret ret = target. Putfile (Uptoken, Key, FilePath, extra);
Return data format: {"hash": "Fvipqyymwi0gvgc7_nud8ovbuj85", "Key": "55456.amr", "Persistentid": "z0.57eb86a945a2652644d64308" }
Returnret. Response.tostring ();
}

6. Finally, the converted files are downloaded from seven cow space to the current server.

The code is as follows Copy Code
<summary>
Download
</summary>
<param name= "Key" > Nicely formatted file name </param>
<param name= "Savepath" > Save path after download </param>
<returns></returns>
Privatestringdownload (Stringkey,stringsavepath)
{
Constructs the private space needs to generate the download link which you help to place in the space the domain name plus to download the filename
Stringbaseurl = "http://***.###.com/" + key;
Call the MakeRequest method to generate a private download link
Stringprivate_url = Getpolicy.makerequest (BaseURL);
Download files
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create (Private_url);
Req. method = ' Get ';
using (WebResponse WR = req. GetResponse ())
{
HttpWebResponse myresponse = (httpwebresponse) req. GetResponse ();
Stringstrpath = MyResponse.ResponseUri.ToString ();
WebClient mywebclient =newwebclient ();
Try
{
Mywebclient. DownloadFile (strpath, Savepath);
}
catch (Exception ex)
{
Savepath = ex. ToString ();
}
}
Returnsavepath;
}

OK, Conversion complete! Attached to the effect of a picture:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.