如何发挥非PCM文件或将其转换为PCM上飞? [英] How to play non-PCM file or convert it to PCM on the fly ?

查看:390
本文介绍了如何发挥非PCM文件或将其转换为PCM上飞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code可以与一些wav文件,但与其他人我得到InvalidOperationException异常是未处理。消息=声音API只支持播放PCM波形文件。

The following code works with some wav files, but with others I get, "InvalidOperationException was unhandled. Message=Sound API only supports playing PCM wave files."

var webClient = new WebClient();
webClient.DownloadFile(url, fileName);
var fileSound = new SoundPlayer(fileName);
fileSound.PlaySync();

有没有一种方法以编程方式检查是否WAV文件是坏(不是PCM波形文件),然后根据需要将其转换?

Is there a way to programmatically check if a wav file is "bad" (not a PCM wave file) and then convert it as necessary?

什么是奇怪的是,code。在传统的Delphi应用程序的工作原理 - 所有的wav文件中发挥就好了。这里的德尔福code:

What is odd is that the code works in the legacy Delphi app - all of the wav files play just fine. Here's the Delphi code:

filename := GetEnvironmentVariable('TEMP')+'\archieAndDingbat.wav';
URLDownloadToFile(nil, PChar(url), PChar(filename), 0, nil);
PlaySound(filename);

我看着在资源管理器中两个文件的属性,我看到有,确实有差别。对于不播放该文件,它的音频格式为PCM;不会玩的是CCITT U-法。

I looked at the properties of the two files in Explorer, and I see that there is, indeed, a difference. For the file that does play, its audio format is PCM; the one that won't play is CCITT u-Law.

所以...我要么需要一种方法来从CCITT U-法转换为PCM动态下载这些文件后(他们是从网址下载并本地播放)或播放这些文件或许比以不同的方式PlaySync()...

So...I either need a way to convert from CCITT u-Law to PCM on the fly after downloading these files (they are download from an url and then played locally) OR perhaps a different way of playing these files than PlaySync() ...

推荐答案

要做到这一点的方法是使用newkie的code。在<一个href=\"http://www.$c$cproject.com/Articles/175030/PlaySound-A-Better-Way-to-Play-Wav-Files-in-C?msg=4366037#xx4366037xx\" rel=\"nofollow\">http://www.$c$cproject.com/Articles/175030/PlaySound-A-Better-Way-to-Play-Wav-Files-in-C?msg=4366037#xx4366037xx

The way to do it is to use newkie's code at: http://www.codeproject.com/Articles/175030/PlaySound-A-Better-Way-to-Play-Wav-Files-in-C?msg=4366037#xx4366037xx

在我的情况下,至少,我只好全部小写字母x的而改变为大写X的,不过,要得到它的工作。

In my case, at least, I had to change all of the lowercase x's to uppercase x's, though, to get it to work.

这篇关于如何发挥非PCM文件或将其转换为PCM上飞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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