none
How to use PushAudioInputStream? RRS feed

  • Question

  • As an audio library I use NAudio.
    y code for speech recognition:
                pushStream = AudioInputStream.CreatePushStream();
                var reader = new Mp3FileReader(@"D:\Data\33.mp3");
                var newFormat = new WaveFormat(16000, 16, 1);
    
    
                pushStream = AudioInputStream.CreatePushStream();
                using (var conversionStream = new WaveFormatConversionStream(newFormat, reader))
                {
                    int read;
                    Byte[] buffer = new byte[conversionStream.WaveFormat.AverageBytesPerSecond];
                    while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        pushStream.Write(buffer, read);
                    }
                }



    The problem is that at the current code recognition though goes, but absolutely incorrect result if directly from a file.
    And the duration of the recording when recognition for some reason more than 3 minutes, although the original 54 seconds.
    Thursday, November 14, 2019 10:26 AM

All replies

  • Hi MacroMax,

    Thanks for reaching out to us. PushAudioInputStream Class represents memory backed push audio input stream used for custom audio input configurations. There are 2 constructors:

    Constructors

    PushAudioInputStream()

    Creates a memory backed PushAudioInputStream using the default format (16 kHz, 16 bit, mono PCM).

    PushAudioInputStream(AudioStreamFormat)

    Creates a memory backed PushAudioInputStream with the specified audio format. Currently, only WAV / PCM with 16-bit samples, 16 kHz sample rate, and a single channel (Mono) is supported. When used with Conversation Transcription, eight channels are supported.

    Fields

    isDisposing

    isDisposing is a flag used to indicate if object is being disposed.

    (Inherited from AudioInputStream)

    Methods

    Close()

    Closes the stream.

    Dispose()

    Dispose of associated resources.

    (Inherited from AudioInputStream)
    Dispose(Boolean)

    This method performs cleanup of resources. The Boolean parameter disposing indicates whether the method is called from Dispose() (if disposing is true) or from the finalizer (if disposing is false). Derived classes should override this method to dispose resource if needed.

    (Inherited from AudioInputStream)
    SetProperty(PropertyId, String)

    Set value of a property associated to data buffer. The properties of the audio data should be set before writing the audio data. Added in version 1.5.0

    SetProperty(String, String)

    Set value of a property associated to data buffer. The properties of the audio data should be set before writing the audio data. Added in version 1.5.0

    Write(Byte[])

    Writes the audio data specified by making an internal copy of the data. Note: The dataBuffer should not contain any audio header.

    Write(Byte[], Int32)

    Writes the audio data specified by making an internal copy of the data.

    Could you please check above first to see if there anything wrong. Also, please let us know if you still have any challenge. 

    Regards,

    Yutong

    Saturday, November 16, 2019 11:57 AM
    Moderator