이 페이지가 유용했습니까?
이 콘텐츠에 대한 여러분의 의견은 중요합니다. 의견을 알려주십시오.
추가 의견
1500자 남음
내보내기(0) 인쇄
모두 확장

RecognizedAudio.WriteToAudioStream 메서드

Write entire audio to a stream as raw data.

네임스페이스: System.Speech.Recognition
어셈블리: System.Speech(system.speech.dll)

public void WriteToAudioStream (
	Stream outputStream
)
public void WriteToAudioStream (
	Stream outputStream
)
public function WriteToAudioStream (
	outputStream : Stream
)
적용할 수 없음.

매개 변수

outputStream

Any valid System.IO.Stream object, to which an application wishes to write audio data in binary format.

Audio data is written to outputStream in pure binary, no structure (such as Wave format) is applied.

The format of data written by WriteToAudioStream is in the same format as that written by

.WriteToWaveStream exclusive of the prepended Wave header.

The example below show a testing routine that uses WriteToWaveStream, and WriteToAudioStream to write all the recognized audio to a stream, as well as GetRange to write selected portions of that audio to a stream.

참고:

Because of the granularity of ticks and the non-zero size of the wave header, the size of a write to stream generated from a call such as GetRange(newTimeSpan(0),newTimeSpan(audio.Duration.Ticks/2) may not be exactly half that of the write from calls such as WriteToWaveStream(waveStream) or WriteToAudioStream(audioStream). The example below takes this into account.


public void AudioRangeTest (RecognitionResult recognitionResult)
{
  RecognizedAudio audio = recognitionResult.Audio;
  
  // Write to stream using WriteToAudioStream
  MemoryStream audioStream = new MemoryStream ();
  audio.WriteToAudioStream (audioStream);
  audioStream.Flush ();

  // Write to stream using WriteToWave
  MemoryStream waveStream = new MemoryStream ();
  audio.WriteToWaveStream (waveStream);
  waveStream.Flush ();

  //Now check that the WriteToWave write is slightly bigger than the 
  //WriteToAudioStream, due to Wave Formatting.
if (audioStream.Length != waveStream.Length - 16 ) ){
    MessageBox.Show(String.Format("Error: length of stream write by WriteToWaveStream(waveStream) is not 16 bytes larger than that of GetRange(new TimeSpan (0), audio.Duration)"));

  //Now do the same with GetRange
  Stream rangeStreamFull = new MemoryStream ();
  RecognizedAudio range = audio.GetRange (new TimeSpan (0), audio.Duration);
  range.WriteToWaveStream (rangeStreamFull);
  rangeStreamFull.Flush ();
  rangeStreamFull.Close ();
  if (rangeStreamFull.Length != audioStream.Length){
    MessageBox.Show(String.Format("Error: length of stream write by WriteToAudioStream(waveStream) does not match that of GetRange(new TimeSpan (0), audio.Duration)"));
}
//Now we test retrieving the first half the audio
    rangeStreamHalf = new MemoryStream ();
    range = audio.GetRange (new TimeSpan (0), 
                   new TimeSpan (audio.Duration.Ticks / 2));
    range.WriteToWaveStream (rangeStreamHalf);
    rangeStreamHalf.Flush ();
    rangeStreamHalf.Close ();
    if ( ! (rangeStreamHalf.Length >= waveStream.Length / 2 - 20 
         && rangeStreamHalf.Length <= waveStream.Length / 2 + 50)){
      MessageBox.Show(String.Format("Error: When retrieving the first half of audio, length of audio.GetRange (new TimeSpan (0), new TimeSpan (audio.Duration.Ticks / 2)) is not approximately half that of WriteToWaveStream(waveStream)."));
    }
    //Now we test retrieving the second half the audio
    rangeStream = new MemoryStream ();
    range = audio.GetRange (new TimeSpan (audio.Duration.Ticks / 2), 
                   new TimeSpan (audio.Duration.Ticks / 2));
    range.WriteToWaveStream (rangeStream);
    rangeStream.Flush ();
    rangeStream.Close ();
    if ( ! (rangeStreamHalf.Length >= waveStream.Length / 2 - 20 
         && rangeStreamHalf.Length <= waveStream.Length / 2 + 50)){
      MessageBox.Show(String.Format("Error: When retrieving the first half of audio, length of audio.GetRange (new TimeSpan (0), new TimeSpan (audio.Duration.Ticks / 2)) is not approximately half that of WriteToWaveStream(waveStream)."));
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Microsoft .NET Framework 3.0은 Windows Vista, Microsoft Windows XP SP2 및 Windows Server 2003 SP1에서 지원됩니다.

.NET Framework

3.0에서 지원

커뮤니티 추가 항목

추가
표시:
© 2015 Microsoft