Пример #1
0
 internal SpeechSeg(TTSVoice voice, AudioData audio)
 {
     _voice = voice;
     _audio = audio;
 }
Пример #2
0
 internal void PlayWaveFile(AudioData audio)
 {
     try
     {
         if (!string.IsNullOrEmpty(audio._mimeType))
         {
             WAVEFORMATEX wAVEFORMATEX = default(WAVEFORMATEX);
             wAVEFORMATEX.nChannels       = 1;
             wAVEFORMATEX.nSamplesPerSec  = 8000;
             wAVEFORMATEX.nAvgBytesPerSec = 8000;
             wAVEFORMATEX.nBlockAlign     = 1;
             wAVEFORMATEX.wBitsPerSample  = 8;
             wAVEFORMATEX.cbSize          = 0;
             string mimeType = audio._mimeType;
             if (!(mimeType == "audio/basic"))
             {
                 if (!(mimeType == "audio/x-alaw-basic"))
                 {
                     throw new FormatException(SR.Get(SRID.UnknownMimeFormat));
                 }
                 wAVEFORMATEX.wFormatTag = 6;
             }
             else
             {
                 wAVEFORMATEX.wFormatTag = 7;
             }
             Begin(wAVEFORMATEX.ToBytes());
             try
             {
                 byte[] array = new byte[(int)audio._stream.Length];
                 audio._stream.Read(array, 0, array.Length);
                 Play(array);
             }
             finally
             {
                 WaitUntilDone();
                 End();
             }
         }
         else
         {
             BinaryReader binaryReader = new BinaryReader(audio._stream);
             try
             {
                 byte[] waveFormat = GetWaveFormat(binaryReader);
                 if (waveFormat == null)
                 {
                     throw new FormatException(SR.Get(SRID.NotValidAudioFile, audio._uri.ToString()));
                 }
                 Begin(waveFormat);
                 try
                 {
                     while (true)
                     {
                         DATAHDR dATAHDR = default(DATAHDR);
                         if (audio._stream.Position + 8 >= audio._stream.Length)
                         {
                             break;
                         }
                         dATAHDR._id  = binaryReader.ReadUInt32();
                         dATAHDR._len = binaryReader.ReadInt32();
                         if (dATAHDR._id == 1635017060)
                         {
                             byte[] buffer = Helpers.ReadStreamToByteArray(audio._stream, dATAHDR._len);
                             Play(buffer);
                         }
                         else
                         {
                             audio._stream.Seek(dATAHDR._len, SeekOrigin.Current);
                         }
                     }
                 }
                 finally
                 {
                     WaitUntilDone();
                     End();
                 }
             }
             finally
             {
                 ((IDisposable)binaryReader).Dispose();
             }
         }
     }
     finally
     {
         audio.Dispose();
     }
 }
Пример #3
0
 internal void AddAudio(AudioData audio)
 {
     AddNewSeg(null, audio);
     _fNotInTextSeg = true;
 }