Socket
Book a DemoInstallSign in
Socket

charisma-sdk-js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

charisma-sdk-js

Charisma.ai SDK for Javascript (browser)

0.2.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Charisma.ai SDK for JavaScript

Usage

yarn add charisma-sdk-js

The script can be pulled straight into the browser.

<script src="./charisma-sdk.js"></script>
<script>
  (async function () {
    const charisma = await Charisma.connect({ storyId: 13 });
    charisma.on('start-typing', () => { ... });
    charisma.on('stop-typing', () => { ... });

    charisma.on('reply', (data) => {
      if (data.reply.speech) {
        charisma.speak(data.reply.speech.data);
      }
    });

    charisma.start({ ... });
    charisma.reply({ ... });
  }){}
</script>

Charisma.connect

Use this to connect to Charisma and set up a new playthrough.

  • storyId (number): The id of the story that you want to create a new playthrough for. The story must be published, unless a Charisma.ai user token has been passed and the user matches the owner of the story.
  • version (number, optional): The version of the story that you want to create a new playthrough for. If omitted, it will default to the most recent version. To get the debug story, pass -1.
  • userToken (string, optional): If the story is unpublished, pass a userToken to be able to access your story.

Returns a promise that resolves once the socket has connected.

const charisma = await Charisma.connect({
  "storyId": 12,
  "version": 4,
  "userToken": "..."
})

Events

To interact with the story, events are sent backwards and forwards along the websocket.

Events sent from client

charisma.start({ ... })

{
  "startNodeId": 12, // Optional, default undefined
  "speech": true // Optional, default false
}

charisma.reply({ ... })

{
  "message": "Please reply to this!",
  "speech": true // Optional, default false
}

Events received by client

charisma.on('reply', (data) => { ... })

{
  "reply": {
    "message": "Greetings and good day.",
    "character": "Ted Baker",
    "avatar": "https://s3.charisma.ai/...",
    "speech": "...", // Stringified buffer
    "metadata": {
      "myMetadata": "someValue"
    }
  },
  "endStory": false,
  "path": [{ "id": 1, "type": "edge" }, { "id": 2, "type": "node" }]
}

charisma.on('start-typing', () => { ... })

This event has no additional data.

charisma.on('stop-typing', () => { ... })

This event has no additional data.

charisma.on('recognise', (message) => { ... })

To be used in conjunction with speech recognition (see below).

charisma.on('recognise-interim', (message) => { ... })

To be used in conjunction with speech recognition (see below).

Utils

To help you with speech-to-text and text-to-speech:

charisma.speak(data)

e.g.

charisma.on("reply", data => {
  if (data.reply.speech) {
    charisma.speak(data.reply.speech.data);
  }
});

charisma.startListening()

Starts browser speech recognition (Google Chrome only). charisma will then emit recognise-interim (player hasn't finished speaking, this is the current best guess) and recognise (player has finished speaking and we're confident about the result) events.

The speech recognition will automatically pause when a character is speaking via charisma.speak.

charisma.stopListening()

Stops browser speech recognition (Google Chrome only).

Questions

For further details or any questions, feel free to get in touch with ben@charisma.ai

FAQs

Package last updated on 29 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.