| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Speech.AudioFormat;
- using System.Speech.Synthesis;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Web;
- using CallCenter.Utility.Common;
- using SpeechLib;
- namespace CallCenter.Utility
- {
- public class TtsHelper
- {
- public static string GetAudioPath(string text)
- {
- if (!string.IsNullOrEmpty(text))
- {
- string filename = CommonHelper.MD5(text) + ".wav";
- string path = HttpContext.Current.Server.MapPath("..") + "\\Audio\\";
- if (!Directory.Exists(path)) Directory.CreateDirectory(path);
- string pathfile = path + filename;
- if (!File.Exists(pathfile))
- {
- File.Create(pathfile).Dispose();
- Task.Factory.StartNew(() =>
- {
- SpeechSynthesizer synth = new SpeechSynthesizer();
- SpeechAudioFormatInfo wavFromat = new SpeechAudioFormatInfo(EncodingFormat.Pcm, 1024 * 11, 16, 1, 16000, 2, null);
- synth.SetOutputToWaveFile(pathfile, wavFromat);
- synth.Speak(text);
- synth.SetOutputToNull();
- });
- }
- return pathfile;
- }
- else
- {
- return "";
- }
- }
- public static string GetAudioPath1(string text)
- {
- if (!string.IsNullOrEmpty(text))
- {
- string filename = CommonHelper.MD5(text) + ".wav";
- string path = HttpContext.Current.Server.MapPath("..") + "\\Audio\\";
- if (!Directory.Exists(path)) Directory.CreateDirectory(path);
- string pathfile = path + filename;
- if (!File.Exists(pathfile))
- {
- SpFileStream stream = new SpFileStream();
- stream.Open(pathfile, SpeechStreamFileMode.SSFMCreateForWrite, false);
- SpVoice sv = new SpVoice();
- sv.AudioOutputStream = stream;
- sv.Speak(text);
- sv.WaitUntilDone(Timeout.Infinite);
- stream.Close();
- }
- return pathfile;
- }
- else
- {
- return "";
- }
- }
- }
- }
|