# generation/streamers

* [generation/streamers](#module_generation/streamers)
    * [.TextStreamer](#module_generation/streamers.TextStreamer)
        * [`new TextStreamer(tokenizer, options)`](#new_module_generation/streamers.TextStreamer_new)
        * [`.put(value)`](#module_generation/streamers.TextStreamer+put)
        * [`.end()`](#module_generation/streamers.TextStreamer+end)
        * [`.on_finalized_text(text, stream_end)`](#module_generation/streamers.TextStreamer+on_finalized_text)
    * [.WhisperTextStreamer](#module_generation/streamers.WhisperTextStreamer)
        * [`new WhisperTextStreamer(tokenizer, options)`](#new_module_generation/streamers.WhisperTextStreamer_new)
        * [`.put(value)`](#module_generation/streamers.WhisperTextStreamer+put)

* * *

## generation/streamers.TextStreamer

Simple text streamer that prints the token(s) to stdout as soon as entire words are formed.

**Kind**: static class of [generation/streamers](#module_generation/streamers)  

* [.TextStreamer](#module_generation/streamers.TextStreamer)
    * [`new TextStreamer(tokenizer, options)`](#new_module_generation/streamers.TextStreamer_new)
    * [`.put(value)`](#module_generation/streamers.TextStreamer+put)
    * [`.end()`](#module_generation/streamers.TextStreamer+end)
    * [`.on_finalized_text(text, stream_end)`](#module_generation/streamers.TextStreamer+on_finalized_text)

* * *

### `new TextStreamer(tokenizer, options)`

  
    
      ParamTypeDefaultDescription
    
  
  

    tokenizerPreTrainedTokenizer
    
    optionsObject
    
    [options.skip_prompt]booleanfalseWhether to skip the prompt tokens

    
    [options.skip_special_tokens]booleantrueWhether to skip special tokens when decoding

    
    [options.callback_function]functionFunction to call when a piece of text is ready to display

    
    [options.token_callback_function]functionFunction to call when a new token is generated

    
    [options.decode_kwargs]Object{}Additional keyword arguments to pass to the tokenizer&#39;s decode method

      

* * *

### `textStreamer.put(value)`

Receives tokens, decodes them, and prints them to stdout as soon as they form entire words.

**Kind**: instance method of [TextStreamer](#module_generation/streamers.TextStreamer)  

  
    
      ParamType
    
  
  

    valueArray
      

* * *

### `textStreamer.end()`

Flushes any remaining cache and prints a newline to stdout.

**Kind**: instance method of [TextStreamer](#module_generation/streamers.TextStreamer)  

* * *

### `textStreamer.on_finalized_text(text, stream_end)`

Prints the new text to stdout. If the stream is ending, also prints a newline.

**Kind**: instance method of [TextStreamer](#module_generation/streamers.TextStreamer)  

  
    
      ParamType
    
  
  

    textstring
    
    stream_endboolean
      

* * *

## generation/streamers.WhisperTextStreamer

Utility class to handle streaming of tokens generated by whisper speech-to-text models.
Callback functions are invoked when each of the following events occur:
 - A new chunk starts (on_chunk_start)
 - A new token is generated (callback_function)
 - A chunk ends (on_chunk_end)
 - The stream is finalized (on_finalize)

**Kind**: static class of [generation/streamers](#module_generation/streamers)  

* [.WhisperTextStreamer](#module_generation/streamers.WhisperTextStreamer)
    * [`new WhisperTextStreamer(tokenizer, options)`](#new_module_generation/streamers.WhisperTextStreamer_new)
    * [`.put(value)`](#module_generation/streamers.WhisperTextStreamer+put)

* * *

### `new WhisperTextStreamer(tokenizer, options)`

  
    
      ParamTypeDefaultDescription
    
  
  

    tokenizerWhisperTokenizer
    
    optionsObject
    
    [options.skip_prompt]booleanfalseWhether to skip the prompt tokens

    
    [options.callback_function]functionFunction to call when a piece of text is ready to display

    
    [options.token_callback_function]functionFunction to call when a new token is generated

    
    [options.on_chunk_start]functionFunction to call when a new chunk starts

    
    [options.on_chunk_end]functionFunction to call when a chunk ends

    
    [options.on_finalize]functionFunction to call when the stream is finalized

    
    [options.time_precision]number0.02Precision of the timestamps

    
    [options.skip_special_tokens]booleantrueWhether to skip special tokens when decoding

    
    [options.decode_kwargs]Object{}Additional keyword arguments to pass to the tokenizer&#39;s decode method

      

* * *

### `whisperTextStreamer.put(value)`

**Kind**: instance method of [WhisperTextStreamer](#module_generation/streamers.WhisperTextStreamer)  

  
    
      ParamType
    
  
  

    valueArray
      

* * *

