在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();
}