在line player.PlaySync()中出现错误

时间:2018-12-06 12:15:25

标签: c# .net

player.PlaySync()行中出现错误。我正在创建.wav文件。它显示了一个错误

  

“文件位于   D:\ Seo-app \ SEO-自动化页面生成.APP \ SEO-自动化页面生成.APP \ Download \ Autoplay.wav   不是有效的wave文件。”

var response = client.SynthesizeSpeech(input, voice, config);

int count = 1;
string virtualPath = HttpContext.Server.MapPath("/Download/");
if (!Directory.Exists(virtualPath))
    Directory.CreateDirectory(virtualPath);
string fullPath = HttpContext.Server.MapPath("/Download/Autoplay.wav");
string fileNameOnly = Path.GetFileNameWithoutExtension(fullPath);
string extension = Path.GetExtension(fullPath);
string path = Path.GetDirectoryName(fullPath);

while (System.IO.File.Exists(fullPath))
{
    string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
    fullPath = Path.Combine(path, tempFileName + extension);
}

using (Stream output = System.IO.File.Create(fullPath))
{
    response.AudioContent.WriteTo(output);
}
using (SoundPlayer player = new SoundPlayer())
{
    player.SoundLocation = HttpContext.Server.MapPath("/Download/Autoplay.wav");

    player.PlaySync();
}

0 个答案:

没有答案