0.2.2 • Published 4 months ago

@speechmatics/flow-client v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Speechmatics Flow client 🤖

Official Javascript client for the Speechmatics Flow API.

Installation

npm i @speechmatics/flow-client

!WARNING
For React Native, make sure to install the event-target-polyfill package, or any other polyfill for the EventTarget class

Usage

The two main exports from this package are the FlowClient class, and the fetchPersonas function.

The FlowClient class is an EventTarget. You can listen for incoming events including audio and transcription messages:

import { FlowClient, AgentAudioEvent } from "@speechmatics/flow-client";
const flowClient = new FlowClient('wss://flow.api.speechmatics.com', { appId: "example" });

function onAgentAudio(audio: AgentAudioEvent) {
  // audio.data is PCM16_SLE data. How you play this depends on your environment
  myAudioPlayFunction(audio.data)
}

flowClient.addEventListener("agentAudio", onAgentAudio);

flowClient.startConversation(YOUR_JWT, {
  config: {
    template_id: "flow-service-assistant-amelia",
    template_variables: {},
  },
  // Optional, this is the default
  audio_format: {
    type: 'raw',
    encoding: 'pcm_s16le',
    sample_rate: 16000,
  },
});

// PCM audio can be sent to the client (either f32 or int16 depending on the audio_format defined above)
function onPCMAudio(audio: Int16Array) {
  flowClient.sendAudio(audio);
}


function onSessionEnd() {
  // Ends conversation and closes websocket
  flowClient.endConversation();

  // Event listeners can also be removed like so
  flowClient.removeEventListener("agentAudio", onAgentAudio);
}

React hooks

See the package @speechmatics/flow-client-react for integration with React based projects.

0.1.3-rc1

7 months ago

0.2.1

5 months ago

0.1.2

7 months ago

0.2.0

6 months ago

0.1.1

8 months ago

0.1.3-alpha1

6 months ago

0.1.2-alpha.3

7 months ago

0.1.2-alpha.2

7 months ago

0.1.2-alpha.5

7 months ago

0.1.2-alpha.4

7 months ago

0.2.2

4 months ago

0.1.2-alpha.1

7 months ago

0.1.0

8 months ago

0.0.1-alpha.19

8 months ago

0.0.1-alpha.18

8 months ago

0.0.1-alpha.12

8 months ago

0.0.1-alpha.11

8 months ago

0.0.1-alpha.14

8 months ago

0.0.1-alpha.13

8 months ago

0.0.1-alpha.16

8 months ago

0.0.1-alpha.15

8 months ago

0.0.1-alpha.17

8 months ago

0.0.1-alpha.10

8 months ago

0.0.1-alpha.9

8 months ago

0.0.1-alpha.8

8 months ago

0.0.1-alpha.7

8 months ago

0.0.1-alpha.6

8 months ago

0.0.1-alpha.5

8 months ago

0.0.1-alpha.4

8 months ago

0.0.1-alpha.3

8 months ago

0.0.1-alpha.2

8 months ago

0.0.1-alpha.1

8 months ago

0.0.1-alpha.0

8 months ago