Coder Social home page Coder Social logo

chat-ai-npcs-video-resources's Introduction

chat-ai-npcs-video-resources

chat-ai-npcs-video-resources

Code for video "Create Intelligent NPCs using Chat AI!", https://youtu.be/RSzeqjKJABk

Currently this contains code for:

  • speech to text
  • text to speech
  • wave converters (which are from third-parties)
  • wrappers for handling conversations, and conversation state, with chatgpt and gpt3

ThirdParty/Wav

  • SavWav.cs: convert AudioClips into byte arrays, that you can send to speech to text.

Given AudioClip clip:

    int numSamples = (int)(clip.frequency * clipElapsedTime);
    float[] clipData = new float[numSamples];
    clip.GetData(clipData, 0);
    byte[] wavBytes = SavWav.SamplesToBytes(clip.frequency, clipData);
  • WAV.cs: convert byte arrays of WAV data into data you can load into an AudioClip.

(In fact, if you look at GoogleTTS, it shows you how to use WAV.cs; and it calls it for you automatically)

Speech to text

  • first use SavWav.cs to convert the AudioClip into wave bytes, then pick one of the converters, e.g. OpenAIWhisperOpenAI, and use like:
SpeechToText speechtotext = new OpenAIWhisperOpenAI()
SpeechToTextResult result = await speechtotext.Transcribe(wavBytes);

text to speech

  • pick one of the converters, e.g. PolyTTS, then do e.g.
AudioClip clip = PolyTTS.SayText("en", false, "Hi guys!");

chatgpt, gpt3 conversation wrappers

E.g. for ChatGPT:

ILLMConversation conversation = new ChatGPTConversation();
conversation.AddPrompt("You are Nora, a magician from the north.");
conversation.AddQuestion("What is your name?");
await foreach(string sentence in conversation.SendStreaming()) {
    // do something with sentence here :)
}

Same interface works for GPT3Conversation.

Auth

This code assumes you have a class Auth.cs, containing the various api keys, such as OpenAI key etc.

You can copy and paste Auth.cs.templ, and fill in the various keys you need.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.