参考地址:
https://blog.csdn.net/weixin_30635053/article/details/95714024
官方:https://docs.microsoft.com/en-us/dotnet/api/system.speech.synthesis.speechsynthesizer?view=netframework-4.8
问题描述:软件系统需要,控制电脑发出提示声音。
之前采用的是[DllImport] ,这种方式控制台运行没有问题,IIS发布就没有声音了,基于百度编程没有搜索到对应的解决方案,也尝试了很多种方式也没有解决;
之后采用SpeedSynthesis类,语音转文字代替,是的电脑发出提示应
[DllImport("winmm.dll")]
public static extern bool PlaySound(String Filename, int Mod, int Flags);
PlaySound(Filename, 0, 0);
环境描述:电脑win7系统 ,.net core v2.1
1、安装包System.Speech,引入命名空间System.Speech.Synthesis
2 代码
public static SpeechSynthesizer speechx = new SpeechSynthesizer();
public static void sound()
{
speechx.SetOutputToDefaultAudioDevice();
//speech.Rate = 1;
//speech.SelectVoice("Microsoft Huihui Desktop");//设置播音员(中文)
//speech.SelectVoice("Microsoft Anna"); //英文 Microsoft Huihui Desktop,Microsoft Zira Desktop,
//speech.Volume = 100;
speechx.SpeakAsync("扫码成功");//语音阅读方法
}
3、IIS 发布,正常发布就可以了
注意:把应用程序池的进程标识改成LocalSystem,能正常生成语音文件了。



