"必须已经浮点"转换音频文件转换成WAV文件时, [英] "Must be already floating point" when converting an audio file into wav file

查看:593
本文介绍了"必须已经浮点"转换音频文件转换成WAV文件时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我有一个code覆盖一个音频文件为WAV格式更好的质量,减少文件大小。在这里,我使用n音讯文件COM pression源$ C ​​$ c和我有一个例外,当我尝试将该文件转换。


  

必须已经浮点


 公共字符串ConvertToWAV(字符串tempFilePath,串tempFileName,串audioType)
{
    //尝试转换文件,如果失败使用原始文件
    FileInfo的的fileInfo =新的FileInfo(tempFilePath + tempFileName);
    字节[] = FILEDATA新的字节[fileInfo.Length]
    FILEDATA = File.ReadAllBytes(tempFilePath + tempFileName);
    ISampleProvider sampleProvider;
    尝试
    {
        如果(audioType.ToLower()。包含(WAV))
        {
            尝试
            {
                使用(MemoryStream的WAV =新的MemoryStream(FILEDATA))
                {
                    的WaveStream流=新WaveFileReader(WAV);                    WAVEFORMAT目标=新WAVEFORMAT();                    变种S =新RawSourceWaveStream(新的MemoryStream(),新WAVEFORMAT(8000,16,1));
                    变种C =新WaveFor​​matConversionStream(WaveFor​​mat.CreateALawFormat(8000,1)中,s);                    sampleProvider =新WaveToSampleProvider(C);                    WaveFileWriter.CreateWaveFile16(tempFilePath + tempFileName,sampleProvider);                    wav.Close();
                }
            }
            赶上(异常前)
            {
                //我们不能转换的文件,继续使用原始文件。
            }
        }
    }
    赶上(异常前)
    {
        扔恩;
    }
    返回Convert.ToBase64String(FILEDATA);
}


解决方案

最后,我得到了这个问题,即一个解决方案,需要添加一种名为媒体基金会在Windows Server 2012中的工作更好的附加功能。

从服务器管理器使用添加角色和功能向导。跳过通过对功能和选择媒体基金会

Here I have a code for covering a audio file into wav format for better quality and reducing file size. Here I am using naudio file compression source code and I got an exception when I try to convert that file.

Must be already floating point

public string ConvertToWAV(string tempFilePath, string tempFileName, string audioType)
{
    //Try to transform the file, if it fails use the original file            
    FileInfo fileInfo = new FileInfo(tempFilePath + tempFileName);
    byte[] fileData = new byte[fileInfo.Length];
    fileData = File.ReadAllBytes(tempFilePath + tempFileName);
    ISampleProvider sampleProvider;
    try
    {
        if (audioType.ToLower().Contains("wav"))
        {
            try
            {
                using (MemoryStream wav = new MemoryStream(fileData))
                {
                    WaveStream stream = new WaveFileReader(wav);

                    WaveFormat target = new WaveFormat();

                    var s = new RawSourceWaveStream(new MemoryStream(), new WaveFormat(8000, 16, 1));
                    var c = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(8000, 1), s);

                    sampleProvider = new WaveToSampleProvider(c);

                    WaveFileWriter.CreateWaveFile16(tempFilePath + tempFileName, sampleProvider);

                    wav.Close();
                }
            }
            catch (Exception ex)
            {
                //We couldn't convert the file, continue with the original file.                        
            }
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return Convert.ToBase64String(fileData);
}

解决方案

at last i got a solution for this issue ie, need to add kind of additional feature named Media Foundation for the better working in Windows Server 2012.

Use the Add Roles and Features wizard from the Server Manager. Skip through to Features and select Media Foundation

这篇关于"必须已经浮点"转换音频文件转换成WAV文件时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆