Пример #1
0
        public SpeechLibStrategy(Options options, int speedRate, ConvertorFactory.SupportedType supportedType)
        {
            _options = options;
            _supportedType = supportedType;

            Voice = new SpVoice
                {
                    Rate = speedRate,
                };

            SetVoice(Properties.Settings.Default.VoiceName);
        }
Пример #2
0
        public StreamState(Options options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            _packets = new List<Packet>();

            _encoder = OpusEncoder.Create(options.InputSamplingRate, options.InputChannels.Value, options.ApplicationType);
            _encoder.Bitrate = options.BitRate.Value;

            _bytesPerSegment = _encoder.FrameByteCount(options.FrameSize.Value);
        }
Пример #3
0
 public TextToVoiceManager()
 {
     var options = new Options
         {
             OutSamplingRate = SamplingRate.Create(Properties.Settings.Default.SampleRate),
             OutChannels = Channels.Create(Properties.Settings.Default.Channels),
             BitRate = BitRate.Create(Properties.Settings.Default.BitRate)
         };
     _strategy = new SpeechLibStrategy(options, Properties.Settings.Default.SpeedRate,
                                       ConvertorFactory.SupportedType.Opus);
     _voiceName = GetVoiceName();
     _models = new TextToVoiceModelConteiner();
 }
Пример #4
0
 public static BaseStreamConvertor GetConverter(string fileName, Options options, SupportedType type)
 {
     switch (type)
     {
         case SupportedType.Opus :
             {
                 return new OpusStreamConvertor(fileName, options);
             }
         case SupportedType.Mp3:
             {
                 return new WaveToMp3Convertor(fileName, options);
             }
     }
     return null;
 }
Пример #5
0
        private void Convert(string filename, Options options, ConvertorFactory.SupportedType supportedType)
        {
            var strategy = new SpeechLibStrategy(options, 4, supportedType);
            var voices = strategy.GetVoiceNames().ToList();
            Assert.IsTrue(voices.Count() == 2, "voices: " + string.Join(", ", voices));

            var model = new TextToVoiceModel
            {
                CurrentState = TextToVoiceModel.States.Run,
                OutFilePath = filename,
                FilePath = filename
            };

            model.SetText(testText);
            strategy.Execute(model, voices.Last());
        }
Пример #6
0
        public OpusStreamConvertor(string fileName, Options options)
        {
            _fileName = fileName + ".opus";
            _options = options;
            _streamState = new StreamState(options);

            if (File.Exists(_fileName))
            {
                SetGranulePos(_streamState);
            }
            else
            {
                using (var fs = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    SetHeader(_streamState, fs);
                    SetComment(_streamState, fs);
                }
            }
        }
Пример #7
0
 public void SpeechTest()
 {
     var testCase = new[] { 6, 10, 12, 19, 24, 32, 64, 128, 256, 510 };
     var dir = string.Format("test_{0:d_M_yyy_HH_mm_ss}", DateTime.Now);
     Directory.CreateDirectory(dir);
     for (int i = 0; i < testCase.Length; i++)
     {
         string filename = string.Format("{0}\\{1}", dir, testCase[i]);
         var opt = new Options
             {
                 BitRate = BitRate.Create(testCase[i])
             };
         Convert(filename, opt, ConvertorFactory.SupportedType.Opus);
         var fi = new FileInfo(filename + ".opus");
         Assert.IsTrue(fi.Exists);
         Assert.IsTrue(fi.Length > 0);
     }
     string filename2 = string.Format("{0}\\{1}", dir, 1);
     Convert(filename2, new Options(), ConvertorFactory.SupportedType.Mp3);
     var fi2 = new FileInfo(filename2 + ".mp3");
     Assert.IsTrue(fi2.Exists);
     Assert.IsTrue(fi2.Length > 0);
 }
Пример #8
0
 public WaveToMp3Convertor(string fileName, Options options)
 {
     _stream = new FileStream(fileName + ".mp3", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
     var waveFormat = new WaveFormat((int)options.InputSamplingRate.Value, options.InputeBits, options.InputChannels.Value);
     _mp3Writer = new LameMP3FileWriter(_stream, waveFormat, options.BitRate.Value);
 }