1.2.2 • Published 6 months ago

cainode v1.2.2

Weekly downloads
2
License
ISC
Repository
github
Last release
6 months ago

CAINode

A lighweight Unofficial Character.AI API in Node/Deno/Bun JS, It does not require a puppeteer to interact with c.ai because the interaction is conducted with websocket and HTTPS Request (fetch). CAINode is now using ESM. Please read at Getting Started first before using CAINode. GitHub commit activity (branch) GitHub last commit (by committer) GitHub repo size GitHub package.json version (branch)

Features

  • Lightweight library (WebSocket and Fetch)
  • Easy to use
  • Almost all Character.AI Support
    • Voice Call
    • Single/Group chat
    • Image Generate
    • User
    • Persona
    • Explore list

Table of contents

Getting Started

Install

To install CAINode, you can simply do

  • using NPM (Node Package Manager)
    npm install -g cainode
  • Using Deno
    import CAINode from "npm:cainode@latest";
  • Using Bun.JS
    bun install cainode
    Back to the Table of contents

Example usage

  • CommonJS
    (async function() {
        const client = new (await import("cainode")).CAINode();
        await client.login("Your token");
        console.log("Logged in!");
        await client.logout();
    })()
  • TypeScript/ESM
    import {CAINode} from "cainode"
    // import {CAINode} from "npm:cainode@latest"; for Deno
    
    const client = new CAINode();
    
    await client.login("Your token");
    console.log("Logged in!");
    await client.logout();
    Back to the Table of contents

Main Function List

  • login()

    Start client initialization with login, make sure your token is valid so that the login session can run properly.

    To get Character.AI Session Token, You can use generate_token() function.

    await client.login("YOUR_CHARACTER_AI_TOKEN");  
    ParamRequireTypeDescription
    TokentruestringYour Character.AI token used for client login.

    Back to the Table of contents

  • generate_token()

    Generate your Character.AI Token by sending link verification to an email.

    • Without timeout

      await client.generate_token("your@email.com", 0);
    • With timeout (per 2 seconds)

      await client.generate_token("your@email.com", 30); // and it will end in 60 seconds.
    • With callback

      await client.generate_token("your@email.com", 30, function() {
         console.log("Please check your email.")
      }, function() {
         console.log("Time is up! Please try again later.")
      });
      ParamRequireTypeDescription
      emailtruestringYour email to send a verification link.
      timeout_per_2sfalsenumberMax waiting for verification. (default = 30)
      mail_sent_cbfalseFunctionCallback when the mail was sent to the target.
      timeout_cbfalseFunctionCallback when the timeout was reached.

      Back to the Table of contents

  • logout()

    Logout from the client.

    await client.logout();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

User Function List

This class contains variables and methods about the User requirement. For example: Get current information account, Change account, etc about user needs.

  • user.info

    Get current information account.

Example

console.log(client.user.info);
ParamRequireTypeDescription
nonefalsenull-

Back to the Table of contents

  • user.public_info()

    Get user public information account.

    await client.user.public_info();
    ParamRequireTypeDescription
    usernamefalsestringTarget Character.AI username account. (default = null, and it will target to your own account.)

    Back to the Table of contents

  • user.public_info_array()

    Get user public information account. same like public_info(), but this function have less information.

    This function allow to fetch more than one usernames. Using array.

    await client.user.public_info_array();
    ParamRequireTypeDescription
    usernamestrueArray or stringTarget Character.AI username account. can be single (string) or multiple (array).

    Back to the Table of contents

  • user.change_info()

    Change current information account.

    await client.user.change_info();
    ParamRequireTypeDescription
    usernamefalsestringChange your old username to new username.
    namefalsestringChange your old name to new name.
    avatar_rel_pathfalsestringChange your old avatar_rel_path link to new avatar_rel_path link.Warning: avatar_rel_path image link must be generated/uploaded to Character.AI server.
    biofalsestringChange your old bio to new bio.

    Back to the Table of contents

  • user.settings()

    Get account settings information data.

    console.log(client.user.settings)
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • user.refresh_settings()

    Refresh settings. also it will returns the current of the settings. no need to do library_name.user.settings after call this function. You can do console.log() instead.

    await library_name.user.refresh_settings()
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • user.update_settings()

    Update user settings by your own settings manually.

    await library_name.user.update_settings()
    ParamRequireTypeDescription
    settings_objecttrueObjectUser Settings.

    Back to the Table of contents

  • user.public_following_list()

    Get public user following list.

    await client.user.public_following_list();
    ParamRequireTypeDescription
    usernametruestringTarget Character.AI username account.
    page_paramfalsenumberPage parameter.

    Back to the Table of contents

  • user.public_followers_list()

    Get public user followers list.

    await client.user.public_followers_list();
    ParamRequireTypeDescription
    usernametruestringTarget Character.AI username account.
    page_paramfalsenumberPage parameter.

    Back to the Table of contents

  • user.following_list_name()

    Get account following name list.

    await client.user.following_list_name();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • user.followers_list_name()

    Get account followers name list.

    await client.user.followers_list_name();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • user.follow()

    Follow user account.

    await client.user.follow();
    ParamRequireTypeDescription
    usernametruestringTarget Character.AI username account.

    Back to the Table of contents

  • user.unfollow()

    Unfollow user account.

    await client.user.unfollow();
    ParamRequireTypeDescription
    usernametruestringTarget Character.AI username account.

    Back to the Table of contents

  • user.search()

    Search user by name.

    await client.user.search();
    ParamRequireTypeDescription
    usernametruestringTarget Character.AI username account.

    Back to the Table of contents

  • user.liked_character_list()

    Get a list of characters that the account likes.

    await client.user.liked_character_list();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • user.add_muted_words()

    Add muted words.

    Example

    • Array
      await library_name.user.add_muted_words(["hello", "world"])
    • String

      await library_name.user.add_muted_words("hello world")
      ParamRequireTypeDescription
      wordstruestring[] | stringWords that you want to add to the muted words.

      Back to the Table of contents

  • user.remove_muted_words()

    Remove muted words.

    Example

    • Array
      await library_name.user.remove_muted_words(["hello", "world"])
    • String

      await library_name.user.remove_muted_words("hello world")
      ParamRequireTypeDescription
      wordstruestring[] | stringWords that you want to remove from the muted words.

      Back to the Table of contents

  • user.clear_muted_words()

    Clear muted words.

    await library_name.user.clear_muted_words()
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

Image Function List

  • image.generate_avatar()

    Generate avatar image using prompt.

    await client.image.generate_avatar(prompt_name);
    ParamRequireTypeDescription
    prompt_nametruestringPrompt used for generating avatar image.

    Back to the Table of contents

  • image.generate_image()

    Generate image using prompt.

    await client.image.generate_image(prompt_name);
    ParamRequireTypeDescription
    prompt_nametruestringPrompt used for generating AI image.

    Back to the Table of contents

Persona Function List

This class contains variables and methods about the Persona requirement. For example: Create/Edit/Delete Persona, Set persona, Get information about persona.

  • persona.create()

    Create your personality for your character.
await client.persona.create(name, description);
ParamRequireTypeDescription
nametruestringYour persona name
descriptiontruestringDescription of your personality, this section is used to describe yourself so that your AI character knows who you are.

Back to the Table of contents

  • persona.set_default()

    Set your default personality specifically.

    await client.persona.set_default(external_persona_id);
    ParamRequireTypeDescription
    external_persona_idtruestringExternal personality id that you have.

    Back to the Table of contents

  • persona.list()

    Get all your personality data.

    await client.persona.list();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • persona.info()

    Get your personality information.

    await client.persona.info(external_persona_id);
    ParamRequireTypeDescription
    external_persona_idtruestringExternal personality id that you have.

    Back to the Table of contents

  • persona.update()

    Update your personality specifically.

    await client.persona.update(external_persona_id, name, description);
    ParamRequireTypeDescription
    external_persona_idtruestringExternal personality id that you have.
    nametruestringYour new personality name.
    descriptiontruestringYour new personality detail.

    Back to the Table of contents

  • persona.delete()

    Used for deleting your personality spesifically.

    await client.persona.delete(external_persona_id);
    ParamRequireTypeDescription
    external_persona_idtruestringExternal personality id that you have.

    Back to the Table of contents

  • persona.set_character()

    Set a custom personality for your character specifically.

    await client.persona.set_character(character_id, external_persona_id);
    ParamRequireTypeDescription
    character_idtruestringA character id that you want to set a custom personality.
    external_persona_idtruestringYour personality id that you use to let AI characters know who you are.

    Back to the Table of contents

Explore Function List

This class contains functions about the Explore requirement. Example: Featured Character, For you Recommended Character, and etc about Explore.

  • explore.featured()

    Get the list of characters displayed by the character.ai server.
await client.explore.featured();
ParamRequireTypeDescription
nonefalsenull-

Back to the Table of contents

  • explore.for_you()

    Get a list of characters recommended by the character.ai server.

    await client.explore.for_you();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • explore.simillar_char()

    Get the list simillar character from ID character.

    await client.explore.simillar_char(char_id);
    ParamRequireTypeDescription
    char_idtruestringCharacter ID.

    Back to the Table of contents

  • explore.character_categories()

    Get the list of characters from the character category exploration.

    await client.explore.character_categories();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • explore.featured_voices()

    Get a list of featured voices.

    await client.explore.featured_voices();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

Character Function List

This class contains functions about the Character requirement (Single Character, not Group Chat). Example: Sending message to Character, Searching character, botes character, and etc about Character.

  • character.votes()

    Get character vote information.

    await client.character.votes(character_id);
    ParamRequireTypeDescription
    character_idtruestringThe character id you are aiming for.

    Back to the Table of contents

  • character.votes_array()

    Get character vote information in array.

    await client.character.votes_array(character_id);
    ParamRequireTypeDescription
    character_idtruestringThe character id you are aiming for.

    Back to the Table of contents

  • character.vote()

    Used for vote the character.

    await client.character.vote(character_id, vote);
    ParamRequireTypeDescription
    character_idtruestringThe character id you are aiming for.
    votetruebooleanCharacter vote options, true = like, false = dislike, and null = cancel

    Back to the Table of contents

  • character.search()

    Search for a character by name or query.

    await client.character.search(name);
    ParamRequireTypeDescription
    nametruestringSearch queries to find characters.

    Back to the Table of contents

  • character.search_suggest()

    Search character by name and suggested by Character.AI Server

    await client.character.search_suggest(name);
    ParamRequireTypeDescription
    nametruestringCharacter name query.

    Back to the Table of contents

  • character.info()

    Get detailed information about characters.

    await client.character.info(character_id);
    ParamRequireTypeDescription
    character_idtruestringYour character id.

    Back to the Table of contents

  • character.recent_list()

    Get a list of recent chat activity

    await client.character.recent_list();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • character.connect()

    Connect client to character chat

    await client.character.connect(character_id);
    ParamRequireTypeDescription
    character_idtruestringYour character id.

    Back to the Table of contents

  • character.disconnect()

    Disconnecting client from character chat

    await client.character.disconnect();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • character.send_message()

    Send message to character.

    • Example (Default and if you're using character.connect() to connect to the Single Character.)

      • Without manual turn
        await library_name.character.send_message("Your Message", false, "URL Link (you can empty it if you don't want to send it)")
      • With manual turn
        await library_name.character.send_message("Your Message", true, "URL Link (you can empty it if you don't want to send it)")
    • Example (Manual input Character ID and Chat ID)

      • Wtihout manual turn
        await library_name.character.send_message("Your Message", false, "URL Link (you can empty it if you don't want to send it)", {
              char_id: "Input your Character ID here.",
              chat_id: "Input your Chat ID here."
           })
      • With manual turn
          ```js
          await library_name.character.send_message("Your Message", true, "URL Link (you can empty it if you don't want to send it)", {
             char_id: "Input your Character ID here.",
             chat_id: "Input your Chat ID here."
          })
          ```
        ParamRequireTypeDescription
        messagetruestringMessage content.
        manual_turnfalsebooleanIf the value of manual_turn is set to true then the message that the client receives must be generated with character.generate_turn() so that the message is obtained by the client.
        image_urlfalsestringThe image content that the character will see, must be a url and not a file type or a file with a type other than image.
        manual_optfalse{chat_id: string, char_id: string, timeout_ms: number}Manual options. (Must fill if you're not already connected into the Single Character. applies only char_id and chat_id only.)

      Back to the Table of contents

  • character.generate_turn()

    Generating message response from character.

    await client.character.generate_turn();
    ParamRequireTypeDescription
    manual_optfalse{chat_id: string, char_id: string, timeout_ms: number}Manual options. (Must fill if you're not already connected into the Single Character. applies only char_id and chat_id only.)

    Back to the Table of contents

  • character.generate_turn_candidate()

    Regenerate character message.

    await client.character.generate_turn_candidate(turn_id);
    ParamRequireTypeDescription
    turn_idtruestringturn_id or message_id from the character.
    manual_optfalse{chat_id: string, char_id: string, timeout_ms: number}Manual options. (Must fill if you're not already connected into the Single Character. applies only char_id and chat_id only.)

    Back to the Table of contents

  • character.create_new_conversation()

    it will create a new conversation and your current conversation will save on the history.

    • With greeting
      await client.character.create_new_conversation();
    • Without greeting

      await client.character.create_new_conversation(false);
      ParamRequireTypeDescription
      with_greetingfalsebooleanThe character will send you a greeting when you create a new conversation. (Default = true)
      manual_optfalse{char_id: string}Manual Option. (Must fill if you're not already connected into the Single Character.)

      Back to the Table of contents

  • character.delete_message()

    Delete character message.

    await client.character.delete_message(turn_id);
    ParamRequireTypeDescription
    turn_idtruestringturn_id or message_id from the character.
    manual_optfalse{char_id: string, chat_id: string}Manual Options (Must fill if you're not already connected into the Single Character.)

    Back to the Table of contents

  • character.edit_message()

    Edit the character message.

    await client.character.edit_message(candidate_id, turn_id, new_message);
    ParamRequireTypeDescription
    candidate_idtruestring
    turn_idtruestringturn_id or message_id from the character.
    new_messagetruestringNew character message
    manual_optfalse{char_id: string, chat_id: string}Manual Options (Must fill if you're not already connected into the Single Character.)

    Back to the Table of contents

  • character.replay_tts()

    Generate text messages from character to voice audio.

    • if you have Voice ID
      await client.character.replay_tts("Turn ID", "Candidate ID", "fill the Voice Character ID here")
    • if you don't have Voice ID and want to use Voice Query instead

      await client.character.replay_tts("Turn ID", "Candidate ID", "Sonic the Hedgehog", true)
      ParamRequireTypeDescription
      turn_idtruestringturn_id from the character.
      candidate_idtruestringcandidate_id from the character.
      voice_id_or_querytruestringInput Voice character ID or you can use Voice Query.
      using_queryfalsebooleanUsing Query (if You're using Voice Query, then set this parameter to true.)
      manual_optfalse{chat_id: string}Manual Options (Must fill if you're not already connected into the Single Character.)

      Back to the Table of contents

  • character.current_voice()

    Get character current voice info.

    • Auto (you must already connected with character)
      await client.character.current_voice()
    • Manual

      await client.character.current_voice("Character ID")
      ParamRequireTypeDescription
      character_idfalsestringTarget of Character ID. (Must fill if you're not already connected into the Single Character.)

      Back to the Table of contents

  • character.get_category()

    Get category used of the character.

    ```js
    await client.character.get_category()
    ```
    ParamRequireTypeDescription
    character_idtruestringTarget of Character ID.

    Back to the Table of contents

  • character.about()

    Get detailed information of the character about.

    REMEMBER: Specific Character only. if the character have an "about" feature, then you can use this function.
    Otherwise, it return noindex: true, or it means it empty.

    await client.character.about()
    ParamRequireTypeDescription
    short_hashtruestringTarget of Character short hash.

    Back to the Table of contents

  • character.info_detailed()

    Get detailed of the character. but, it will give you a FULL detailed of the Character, including character definition.

    REMEMBER: If the character defined turned to public, then you can use this function.
    Otherwise, it return an empty character data and the status says "do not have permission to view this Character".

    await client.character.info_detailed()
    ParamRequireTypeDescription
    external_idtruestringTarget of Character ID.

    Back to the Table of contents

Group Chat Function List

  • group_chat.list()

    Get all list available group chat in account.

    await client.group_chat.list();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • group_chat.connect()

    Connecting to group chat by the room_id, btw you can't connect the group chat before you create it.

    await client.group_chat.connect(room_id);
    ParamRequireTypeDescription
    room_idtruestringYour group chat id.

    Back to the Table of contents

  • group_chat.disconnect()

    Disconnecting from group chat by the room_id.

    await client.group_chat.disconnect(room_id);
    ParamRequireTypeDescription
    room_idtruestringYour group chat id.

    Back to the Table of contents

  • group_chat.create()

    Create a custom room chat.

    await client.group_chat.create(title_room, character_id);
    ParamRequireTypeDescription
    title_roomtruestringYour custom title room name.
    character_idtruestringYour character id will be added to the group chat.

    Back to the Table of contents

  • group_chat.delete()

    Delete group chat.

    await client.group_chat.delete(room_id);
    ParamRequireTypeDescription
    room_idtruestringYour group chat id.

    Back to the Table of contents

  • group_chat.rename()

    Rename group chat.

    await client.group_chat.rename(new_name, room_id);
    ParamRequireTypeDescription
    new_nametruestringNew name for your group chat.
    room_idtruestringYour group chat id.

    Back to the Table of contents

  • group_chat.join_group_invite()

    Joining group chat using invite code.

    await client.group_chat.join_group_invite(invite_code);
    ParamRequireTypeDescription
    invite_codetruestringThe group chat miinvite code.

    Back to the Table of contents

  • group_chat.char_add()

    Add a character with character_id to the group chat.

    await client.group_chat.char_add(character_id);
    ParamRequireTypeDescription
    character_idtruestringCharacter id to be added to the group chat.

    Back to the Table of contents

  • group_chat.char_remove()

    Remove a character with character_id from the group chat.

    await client.group_chat.char_remove(character_id);
    ParamRequireTypeDescription
    character_idtruestringCharacter id to be removed from the group chat.

    Back to the Table of contents

  • group_chat.send_message()

    Send message to character in group chat.

    await client.group_chat.send_message(message, image_url);
    ParamRequireTypeDescription
    messagetruestringMessage content.
    image_urlfalsestringThe image content that the character will see, must be a url and not a file type or a file with a type other than image.

    Back to the Table of contents

  • group_chat.generate_turn()

    Generating message response character from group chat.

    await client.group_chat.generate_turn();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • group_chat.generate_turn_candidate()

    Regenerate character message.

    await client.group_chat.generate_turn_candidate(turn_id);
    ParamRequireTypeDescription
    turn_idtruestringturn_id or message_id from the character.

    Back to the Table of contents

  • group_chat.reset_conversation()

    Reset conversation in group chat.

    await client.group_chat.reset_conversation();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • group_chat.delete_message()

    Delete character message.

    await client.group_chat.delete_message(turn_id);
    ParamRequireTypeDescription
    turn_idtruestringturn_id or message_id from the character.

    Back to the Table of contents

  • group_chat.edit_message()

    Edit character message in group chat.

    await client.group_chat.edit_message(candidate_id, turn_id, new_message);
    ParamRequireTypeDescription
    candidate_idtruestring
    turn_idtruestringturn_id or message_id from the character.
    new_messagetruestringNew character message

    Back to the Table of contents

  • group_chat.select_turn()

    Select the turn of character chat by yourself.

    await client.group_chat.select_turn(turn_id);
    ParamRequireTypeDescription
    turn_idtruestringturn_id or message_id from the character.

    Back to the Table of contents

Chat Function List

  • chat.history_chat_turns()

    Get a history chat from group or single chat.

    await client.chat.history_chat_turns(chat_id);
    ParamRequireTypeDescription
    chat_idtruestringGroup chat or single chat ID.

    Back to the Table of contents

  • chat.conversation_info()

    Get converastion information.

    await client.chat.conversation_info(chat_id);
    ParamRequireTypeDescription
    chat_idtruestringGroup chat ID or single chat ID.

    Back to the Table of contents

  • chat.history_conversation_list()

    Get list of your history conversation from character. This function is for Single character only.

    • Auto (Already connected to the Single character chat)
      await client.chat.history_conversation_list()
    • Manual

      await client.chat.history_conversation_list("Character ID") 
      ParamRequireTypeDescription
      character_idfalsestringTarget of Character ID.

      Back to the Table of contents

  • chat.set_conversation_chat()

    Set conversation chat, and bring the history chat into current chat. This function is for Single character only.

    await client.chat.set_conversation_chat(chat_id)
    ParamRequireTypeDescription
    chat_idtruestringsingle chat ID.

    Back to the Table of contents

  • chat.pin_message()

    Pin message. This function is for Single character only.

    • Auto (if your're already connected to the single character)
      await client.chat.pin_message("Turn ID")
    • Manual

      await client.chat.pin_message("Turn ID", true, "Chat ID")
      ParamRequireTypeDescription
      turn_idtruestringTurn ID Message.
      pinnedfalsebooleanSet the message pinned or not. (set true if you want to pin the message, set false if you want to unpin the message.)
      chat_idfalsestringChat ID Message. (Set the Chat ID if you not connected to the Single character.)

      Back to the Table of contents

  • chat.list_pinned_message()

    Get list pinned message from chat. This function works only for single character chat.

    await client.chat.list_pinned_message("Chat ID")
    ParamRequireTypeDescription
    chat_idtruestringChat ID Message.

    Back to the Table of contents

  • chat.archive_conversation()

    Archive your conversation. This function works only for single character chat.

    • If you want archive the conversation
      await client.chat.archive_conversation("Chat ID", true)
    • If you want unarchive the conversation

      await client.chat.archive_conversation("Chat ID", false)
      ParamRequireTypeDescription
      chat_idtruestringChat ID message that you want to archive.
      set_archivefalsebooleanSet Archive (to archive the Conversation, you can set it to true. If you want to unarchive the Converastion, you can set it to false.)

      Back to the Table of contents

  • chat.duplicate_conversation()

    Duplicate your conversation. This function works only for single character chat.

    await client.chat.duplicate_conversation("Chat ID", "Turn ID")
    ParamRequireTypeDescription
    chat_idtruestringChat ID message that you want to duplicate.
    turn_idtruestringTurn ID message that you want to duplicate.

    Back to the Table of contents

  • chat.rename_conversation()

    Rename your conversation title. This function works only for single character chat.

    await client.chat.rename_conversation("Chat ID", "Custom Name")
    ParamRequireTypeDescription
    chat_idtruestringChat ID message that you want to rename.
    nametruestringName that you want to rename.

    Back to the Table of contents

Voice Function List

  • voice.user_created_list()

    Get list of user created voice information.

    • Get your own created voice list
      await client.voice.user_list()
    • Get user created voice list

      await client.voice.user_list("username")
      ParamRequireTypeDescription
      usernamefalsestringA username that wants you to check the created voice list.

      Back to the Table of contents

  • voice.info()

    Get a voice information.

    await client.voice.info("Voice ID")
    ParamRequireTypeDescription
    voice_idtruestringA Voice ID that wants you to check the voice information.

    Back to the Table of contents

  • voice.connect()

    WARNING: This feature only supports Single character chat, not Group chat.

    Connect to voice character chat, and this function works only for single character chat.

    • Using Query
      await client.voice.connect("Query", true)
    • Using Voice ID

      await client.voice.connec("Voice ID")

      Example to use

    • Without microphone

      const Speaker = require("speaker"); // import Speaker from "speaker"
      const speaker = new Speaker({
            channels: 1,          // 1 channel
            bitDepth: 16,         // 16-bit samples
            sampleRate: 48000     // 48,000 Hz sample rate
      });
      
      await client.character.connect("Character ID");
      let test = await client.voice.connect("Sonic The Hedgehog", true);
      
      console.log("Character voice ready!");
      
      test.on("frameReceived", ev => {
            speaker.write(Buffer.from(ev.value.data.buffer)); // PCM buffer write into speaker and you'll hear the sound.
      });
      
      await client.character.generate_turn(); // Test is voice character is working or not.
    • With microphone (Voice call)

      const Speaker = require("speaker"); // import Speaker from "speaker"
      const { spawn } = require('child_process'); // import { spawn } from "child_process".
      //for microphone, I'll using sox. so Ineed child_process
      
      const speaker = new Speaker({
            channels: 1,          // 1 channel
            bitDepth: 16,         // 16-bit samples
            sampleRate: 48000     // 48,000 Hz sample rate
      });
      
      const recordMic = spawn('sox', [
            '-q',
            '-t', 'waveaudio', '-d', // Input windows audio (add '-d' if you want set default)
            '-r', '48000',           // Sample rate: 48 kHz
            '-e', 'signed-integer',  // Encoding: signed PCM
            '-b', '16',              // Bit depth: 16-bit
            '-c', '1',               // Channel: 1 (mono)
            '-t', 'raw',             // Output format: raw PCM
            '-'                      // stdout
      ]);
      
      let test = await client.voice.connect("Sonic The Hedgehog", true, true);
      
      console.log("Voice call ready!");
      
      test.on("frameReceived", ev => {
            speaker.write(Buffer.from(ev.value.data.buffer)); // PCM buffer write into speaker and you'll hear the sound.
      });
      
      recordMic.stdout.on("data", data => {
            if (test.is_speech(data)) test.input_write(data); // Mic PCM Buffer output send it to Livekit server.
      });
      ParamRequireTypeDescription
      voice_query_or_idtruestringTarget Voice query or Voice ID.
      using_voice_queryfalsebooleanUsing Voice Query (set it to true if voice_query_or_id using Voice Query)
      using_micfalsebooleanUsing Microphone (You can talk to the Character using Microphone. Livekit needed.)
      mic_optfalse{sample_rate: number, channel: number}Mic options. Default = {sample_rate: 48000, channel: 1}
      manual_optfalse{char_id: string, chat_id: string}Manual Options. (Must fill if you're not connected to the Single Character.)

      Back to the Table of contents

Livekit Function List

  • voice.connect().is_character_speaking

    Check is Character is speaking or not.

    const voice = await client.voice.connect();
    console.log(voice.is_character_speaking)
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • voice.connect().on event

    Get Character.AI Voices (Livekit) data events.

    • dataReceived: Receive Character.AI Livekit data events.
      const voice = await client.voice.connect();
      voice.on("dataReceived", data => {
         console.log(data)
      })
    • frameReceived: Receive audio stream from Livekit Server.
      const voice = await client.voice.connect();
      voice.on("frameReceived", data => {
         console.log(data)
      })
    • disconnected: Notify when the Voice is disconnect.
      const voice = await client.voice.connect();
      voice.on("disconnected", () => {
         console.log("Voice disconnected!")
      })
      Back to the Table of contents
  • voice.connect().input_write

    Send audio PCM raw data to the Livekit Server.

    const voice = await client.voice.connect();
    voice.input_write();
    ParamRequireTypeDescription
    pcm_datatrueBufferPCM Buffer Data.

    Back to the Table of contents

  • voice.connect().is_speech

    this function checking is the PCM buffer frame is silence or not.
    if the PCM Buffer is silence, it will return false. if not, it will return true

    Threshold default: 1000

    Credit: https://github.com/ashishbajaj99/mic/blob/master/lib/silenceTransform.js

    const voice = await client.voice.connect();
    voice.is_speech();
    ParamRequireTypeDescription
    chunktrueBufferPCM Buffer Data.
    ThresholdfalsenumberThreshold. (Default = 1000)

    Back to the Table of contents

  • voice.connect().interrupt_call

    Interrupt while character talking.

    const voice = await client.voice.connect();
    await voice.interrupt_call();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

  • voice.connect().disconnect

    Disconnect from voice character.

    const voice = await client.voice.connect();
    await voice.disconnect();
    ParamRequireTypeDescription
    nonefalsenull-

    Back to the Table of contents

Issues

Feel free to open the issue, I hope this documentation can help you maximally and make it easier for you to use this package.

Thanks to ZTRdiamond for helping me making a documentation.

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

7 months ago

1.1.9

7 months ago

1.1.8

8 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

1 year ago

1.0.0

4 years ago