示例#1
0
 private SpeakerInfo(SpeakerEnums id, string name, string expression)
 {
     this.Id          = id;
     this.Name        = name;
     this.DisplayName = "";
     this.Expression  = expression;
 }
示例#2
0
 public TtsSessionParameters(SpeakerEnums speaker, SpeechSpeedEnums speed, SpeechVolumeEnums volume, int sampleRate)
 {
     this.Speaker    = speaker;
     this.Speed      = speed;
     this.Volume     = volume;
     this.SampleRate = sampleRate;
 }
示例#3
0
        public static string GetName(SpeakerEnums value)
        {
            if (list == null)
            {
                Initialize();
            }

            if (!dic1.ContainsKey(value))
            {
                return(null);
            }
            return(dic1[value].Name);
        }
示例#4
0
        /// <summary>
        /// 把文字转化为声音,多路配置,多种语音
        /// </summary>
        /// <param name="speekText">要转化成语音的文字</param>
        /// <param name="outWaveFlie">把声音转为文件,默认为不生产wave文件</param>
        protected void RawAudioFromFormatText(List <SpeechPart> output, string text)
        {
            try
            {
                string[] lines = text.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.None);
                for (int i = 0; i < lines.Length; i++)
                {
                    int index = output.Count;
                    try
                    {
                        if (lines[i] == null)
                        {
                            continue;
                        }
                        string line = lines[i].Trim();
                        if (line == "")
                        {
                            continue;
                        }

                        int pos = line.IndexOf('#');//#在段中的位置
                        if (pos > 0)
                        {
                            //设定了讲话者时用指定的讲话者说
                            this.Speaker = SpeakerInfo.Parse(line.Substring(0, pos).ToLower());
                            string content = line.Substring(pos + 1, line.Length - pos - 1);

                            RawAudioFromText(output, content);
                        }
                        else if (line.StartsWith("stop"))
                        {//暂停一段时间
                            int seconds = Convert.ToInt32(line.Substring(4, line.Length - 4));

                            RawAudioFromSleep(output, seconds);
                        }
                        else if (line.StartsWith("ting"))
                        {//插入叮铃声
                            RawAudioFromDing(output);
                        }
                        else
                        {
                            RawAudioFromText(output, line);
                        }
                    }
                    finally
                    {
                        if (this.AudioReceived != null)
                        {
                            for (int blockId = index; blockId < output.Count; blockId++)
                            {
                                AudioReceivedEventArgs e = new AudioReceivedEventArgs(
                                    index, lines.Length, output[blockId].RawAudio);
                                this.AudioReceived(this, e);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }