void ISpEngineSite.LoadResource(string uri, ref string mediaType, out IStream stream)
 {
     mediaType = null;
     try
     {
         Stream       stream2    = _site.LoadResource(new Uri(uri, UriKind.RelativeOrAbsolute), mediaType);
         BinaryReader br         = new BinaryReader(stream2);
         byte[]       waveFormat = AudioBase.GetWaveFormat(br);
         mediaType = null;
         if (waveFormat != null)
         {
             WAVEFORMATEX wAVEFORMATEX = WAVEFORMATEX.ToWaveHeader(waveFormat);
             WaveFormatId wFormatTag   = (WaveFormatId)wAVEFORMATEX.wFormatTag;
             if (wFormatTag == WaveFormatId.Pcm || (uint)(wFormatTag - 6) <= 1u)
             {
                 mediaType = "audio/x-wav";
             }
         }
         stream2.Position = 0L;
         stream           = new SpStreamWrapper(stream2);
     }
     catch
     {
         stream = null;
     }
 }
Example #2
0
        /// <summary>
        /// Load a file either from a local network or from the Internet.
        /// </summary>
        void ISpEngineSite.LoadResource(string uri, ref string mediaType, out IStream stream)
        {
            mediaType = null;
#pragma warning disable 56518 // BinaryReader can't be disposed because underlying stream still in use.
            try
            {
                // Get the mime type
                Stream       localStream = _site.LoadResource(new Uri(uri, UriKind.RelativeOrAbsolute), mediaType);
                BinaryReader reader      = new(localStream);
                byte[]       waveFormat  = System.Speech.Internal.Synthesis.AudioBase.GetWaveFormat(reader);
                mediaType = null;
                if (waveFormat != null)
                {
                    WAVEFORMATEX hdr = WAVEFORMATEX.ToWaveHeader(waveFormat);
                    switch ((WaveFormatId)hdr.wFormatTag)
                    {
                    case WaveFormatId.Alaw:
                    case WaveFormatId.Mulaw:
                    case WaveFormatId.Pcm:
                        mediaType = "audio/x-wav";
                        break;
                    }
                }
                localStream.Position = 0;
                stream = new SpStreamWrapper(localStream);
            }
            catch
            {
                stream = null;
            }
#pragma warning restore 56518
        }