Code Monkey home page Code Monkey logo

assemblyai-webrtc-wrapper's Introduction

AssemblyAI WebRTC Wrapper

The AssemblyAI wrapper provides an easy to use interface to stream audio from the browser to the AssemblyAI API for near real-time speech-to-text. For a complete sample project, check out the AssemblyAI Sample WebRTC Project.

Getting started

  1. Clone this repo

  2. Copy or link the cloned repo to your web project's public script folder Example: /js folder

  3. Include the AssemblyAI javascript file in your HTML document

    <script src="public-script-folder/assembly-ai.js"></script>
    

Usage

var assemblyai = new AssemblyAI("your-secret-api-token");

Create an AssemblyAI instance with your API token.

Start recording

assemblyai.startRecording([autoStop, transcriptionCallback, uiCallback])

Begin recording audio stream from browser.

Optional parameters:

  • autoStop: true | false Auto-detect when user is done speaking and stops recording. Requires transcriptionCallback parameter if true.

  • transcriptionCallback: Function to handle result of transcription operation. For example:

    assemblyai.startRecording(true, function(response){
        console.log(response.text);
        console.log(response.confidence);
        console.log(response.id)
    });
    

    Required if autoStop is true.

  • uiCallback: Function to handle any UI operations immediately after recording stops:

    assemblyai.startRecording(true, transcriptionCallback, function(){
        /* Code to update UI immediately after recording stops */
    
        // Change text of record button back from "Recording" to "Record"
        var button = document.getElementById("record-button");
        button.innerText("Record");
    });
    

Cancel recording

assemblyai.cancelRecording()

Cancel audio stream being recorded.

Stop recording

assemblyai.stopRecording(callback)

Stop audio stream being recorded. Recorded audio is sent to the AssemblyAI API for transcription.

  • callback: Function to handle result of transcription operation. For example:

    assemblyai.stopRecording(function(response){
        console.log(response.text);
        console.log(response.confidence);
        console.log(response.id)
    });
    
  • The response argument passed to your callback function will be the following response object returned from the AssemblyAI API:

    Example response object:
    {
      status: 'completed',
      model_id: 'None',
      confidence: '0.9',
      created: '2018-06-25 05:14:28.361123',
      text: 'the weather is nice today',
      id: 5
    }
    

More details can be found in the full AssemblyAI Documentation.

Save recording

assemblyai.saveRecording()

Save the recorded audio stream to disk in audio/wav format.

Sample project

For a complete sample project, check out the AssemblyAI Sample WebRTC Project.

Note

The wrapper utilizes WebRTC to capture audio from the browser. WebRTC requires web projects to be hosted on localhost or an SSL secured domain.

assemblyai-webrtc-wrapper's People

Contributors

dylanbfox avatar

Stargazers

Pablo Schaffner avatar Sujish Patel avatar Leonard Bogdonoff avatar  avatar

Watchers

 avatar James Cloos avatar  avatar Brennan Vincello avatar  avatar

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.