You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
772 B
C#
36 lines
772 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Speech.Synthesis;
|
|
using System.Text;
|
|
|
|
namespace HighWayIot.Common
|
|
{
|
|
public class SpeechStr
|
|
{
|
|
private static readonly Lazy<SpeechStr> lazy = new Lazy<SpeechStr>(() => new SpeechStr());
|
|
|
|
public static SpeechStr Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
|
|
public async void SpeakAsync(string str)
|
|
{
|
|
|
|
SpeechSynthesizer speech = new SpeechSynthesizer();
|
|
speech.Rate = 3;//设置语速
|
|
speech.Volume = 100;//设置音量
|
|
speech.SelectVoice("Microsoft Huihui Desktop");//设置播音员(中文)
|
|
speech.SpeakAsync(str);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|