我有一个在 Asp.Net MVC 5 框架之上使用 C# 编写的应用程序。
我的目标是调用第三方服务来下载波形文件。然后我想把这个文件转换成mp3。最后,我想将 mp3 文件返回为 (byte[]),以允许用户直接从内存下载它。
这是我的代码最终的结果,允许用户从内存下载转换后的文件
public ActionResult Download(int? id)
{
// Download and convert the file
// the variable "someUri" is generated based on the provided id value
byte[] filedata = ConvertToMp3(someUri);
var cd = new System.Net.Mime.ContentDisposition
{
FileName = "filename.mp3",
Inline = true,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(filedata, "audio/mpeg");
}
Run Code Online (Sandbox Code Playgroud)
但我对该方法有疑问ConvertToMp3。
我正在使用NAudio库来转换文件。到目前为止,这是我的代码
public void ConvertToMp3(Uri uri)
{
using (var client = new WebClient())
{
byte[] file = client.DownloadData(uri); …Run Code Online (Sandbox Code Playgroud) 我一直在做一个项目,我需要从 MIC 录制语音并将其上传到网络服务器。我想要 .mp3 格式。为此已经通过本教程。
它在演示结束时工作正常,但是当我使用相同的编码和提供的所有文件时,它会在本地主机和网络上显示错误。
未捕获无法加载内存初始值设定项 Mp3LameEncoder.min.js.mem
我完全按照他们工作并修改了演示中的代码页面中但它不起作用。
我在 ASP.NET C# 中工作并使用 Chrome 作为我的用户代理。
我的文件结构是:
这是示例代码:
<script>
(function () {
var audioContext, gumStream, recorder, input, encodingType, encodeAfterRecord = true, startRecording, stopRecording;
URL = window.URL || window.webkitURL;
var AudioContext = window.AudioContext || window.webkitAudioContext;
//window.AudioContext = window.AudioContext || window.webkitAudioContext;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
startRecording = function () {
var constraints = { audio: true, video: false };
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) …Run Code Online (Sandbox Code Playgroud) 我正在使用SimpleLameLibForAndroid将使用Android中的AudioRecord类创建的pcm文件转换为mp3.我读取了pcm文件并将其编码为mp3,然后将其写入文件中.结果mp3文件,但不正确,它有很多噪音,真的很难理解它是记录pcm文件.这些是录制的音频规格(pcm文件):
private static final int RECORDER_SAMPLERATE = 8000;
private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
int BufferElements2Rec = 1024; // want to play 2048 (2K) since 2 bytes we use only 1024
int BytesPerElement = 2; // 2 bytes in 16bit format
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING, BufferElements2Rec * BytesPerElement);
Run Code Online (Sandbox Code Playgroud)
这是我的代码使用liblame编码mp3并将其写入文件:
//Encoder.Builder(int inSamplerate,int outChannel,int outSampleRate,int outBitrate)
Encoder en = new Encoder.Builder(8000, 1,8000,128).quality(7).create();
private int PCM_BUF_SIZE = 8192;
private int …Run Code Online (Sandbox Code Playgroud)