0.1.1 • Published 5 years ago

calm-lake v0.1.1

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Calm Lake

I want to use a stable stream but there are so many unexpected situations.

Rationale

In mobile, a stream can be broken in many reasons such as changing network AP, signal weakness or a failure from the back-end. If a stream is stable, of course it can be not perfect, I think it will be very useful because we can delete many exception-catch codes.

Examples

Google Speech-to-text Streaming

// First, create a stream proxy with Google Speech-to-text stream.
class GoogleStreamProxy extends BasicStreamProxy<Buffer, SpeechEvent> {
  constructor(
    controller: StreamProxyController,
    private readonly recognizeStream: NodeJS.WritableStream,
  ) {
    super();
    this.recognizeStream
      .on('error', error => this.fire('error', error))
      .on('data', data => {
        this.fire('data', data);
        // https://github.com/vin-ni/Google-Cloud-Speech-Node-Socket-Playground/issues/9
        if (/* is end of utterance */) {
          controller.goNextProxy();
        }
      });
  }

  public send = (data: Buffer) => {
    this.recognzeStream.write(data);
  }

  public destroy = () => {
    this.recognizeStream.end();
  }
}

// Make a lake to be calm.
const lake = calm(async controller => new GoogleStreamProxy(
  controller,
  googleSpeechClient.streamingRecognize(/*request*/)),
)
  .on('data', console.info)
  .on('error', console.warn);

// Send a data into a lake.
lake.send(audioBuffer);

License

MIT

0.1.1

5 years ago

0.1.0

5 years ago