Coder Social home page Coder Social logo

bethechange-tech / aws-transcribe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qasim9872/aws-transcribe

0.0 0.0 0.0 462 KB

A client for Amazon Transcribe using the websockets API

Home Page: https://www.npmjs.com/package/aws-transcribe

License: MIT License

JavaScript 3.36% TypeScript 96.64%

aws-transcribe's Introduction

AWS Transcribe

A client for Amazon Transcribe using the websocket interface

WARNING: This module is now deprecated and will no longer be maintained. Please use the official package provided by amazon, it can be found here

Getting Started

With NPM install the module with: npm install aws-transcribe --save With YARN install the module with: yarn add aws-transcribe

Example

An example of streaming from microphone can be found in src/examples/stream-from-microphone.ts

import { AwsTranscribe, StreamingClient, TranscriptEvent } from "aws-transcribe"

const client = new AwsTranscribe({
    // if these aren't provided, they will be taken from the environment
    accessKeyId: "ACCESS KEY HERE",
    secretAccessKey: "SECRET KEY HERE",
})

const transcribeStream = client
    .createStreamingClient({
        region: "eu-west-1",
        sampleRate: 16000,
        languageCode: "en-US",
    })
    // enums for returning the event names which the stream will emit
    .on(StreamingClient.EVENTS.OPEN, () => console.log(`transcribe connection opened`))
    .on(StreamingClient.EVENTS.ERROR, console.error)
    .on(StreamingClient.EVENTS.CLOSE, () => console.log(`transcribe connection closed`))
    .on(StreamingClient.EVENTS.DATA, (data: TranscriptEvent) => {
        const results = data.Transcript.Results

        if (!results || results.length === 0) {
            return
        }

        const result = results[0]
        const final = !result.IsPartial
        const prefix = final ? "recognized" : "recognizing"
        const text = result.Alternatives[0].Transcript
        console.log(`${prefix} text: ${text}`)
    })

yourStream.pipe(transcribeStream)

API

new AwsTranscribe(clientConfig)

This creates a service wrapper which can then be used to create a streaming client

The clientConfig is optional and can be provided with the following properties:

  • accessKeyId if not provided, the package will look for AWS_ACCESS_KEY_ID environment variable
  • secretAccessKey if not provided, the package will look for AWS_SECRET_ACCESS_KEY environment variable

AwsTranscribe.createStreamingClient(transcribeStreamConfig)

This will create a presigned url using the config and return an instance of StreamingClient which is a wrapper around the websocket. It will decode binary messages coming from AWS and encode messages to binary when sending them

The transcribeStreamConfig is required and must have the following properties:

  • region must be one of "us-east-1", "us-east-2", "us-west-2", "ap-southeast-2", "ca-central-1", "eu-west-1"
  • languageCode must be one of "en-US", "en-AU", "en-GB", "fr-CA", "fr-FR", "es-US"
  • sampleRate must be between 8000 and 44100 - the supported sample rate differs depending on the language code being used. For more information, go here

It may also optionally include:

StreamingClient EVENTS

  • open - when the socket to aws is opened
  • error - any errors sent as part of websocket message or websocket error
  • data - emits the transcription object
  • close - when the socket to aws closes

Debugging

set environment variable to below when running your application.

DEBUG=aws-transcribe:\*

Issues

If you discover a bug, please raise an issue on Github. https://github.com/qasim9872/aws-transcribe/issues

Contribution

Pull requests are very welcome. Please:

  • ensure all tests pass before submitting PR
  • add tests for new features
  • document new functionality/API additions in README.md

License

Copyright (c) 2020 Muhammad Qasim. Licensed under the MIT license.

aws-transcribe's People

Contributors

dependabot[bot] avatar evgenyfadeev avatar igoratron avatar ioga avatar orgads avatar qasim9872 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.