0.5.1 • Published 5 years ago

rev_ai v0.5.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Node JS client library for REV AI

Provides functions to access Rev AI APIs http://rev.ai.

What is Rev AI?

  • Speech to Text service

Installation

To install, run the following command:

npm install rev_ai --save

If you want to install the latest module directly from Github, use the following command:

npm install git+https://github.com/PacoVu/rev_ai

Include it

var revai = require('rev_ai')
var client = new revai.REVAIClient(rev-ai-apikey, version, proxy)

You can find your API key here after logging in your account.

version Optional parameter (defaults to 'v1beta').

proxy Optional parameter. Set a proxy if you're behind a firewall. Here is an example of initiating the client if you're using proxy:

var revai = require('rev_ai')
var client = new revai.REVAIClient(rev-ai-apikey, 'v1beta', 'http://user:pass@proxy.server.com:3128')

Call Rev AI endpoints

// Get account info
client.account(function(err,resp,body){
  console.log(body.balance_seconds/60)
})

// Transcribe an audio file from local storage
var params = {
  media: "sample1.mp3",
  metadata: "This is a sample file from local storage"
}
client.transcribe(params, function(err,resp,body){
  console.log(body)
})

// Transcribe an audio file from url
var params = {
  media_url: "http://www.somewhere.com/audio.mp3",
  metadata: "This is a sample file from a remote url"
}
client.transcribe(params, function(err,resp,body){
  console.log(body)
})

// Get transcription jobs
client.getJobs(params, function(err,res,body){
  for (var job of body){
    console.log(job.status)
    console.log(job.id)
    console.log(job.completed_on)
  }
})

// Get a transcription job by job ID
var jobId=12261294
client.getJobById(jobId, function(err,res,body){
  console.log(body)
  if (body.status == "transcribed"){
    // call getTranscription to get the transcription
    // client.getTranscription(body.id, callback)
  }
})

// Get getTranscription
var callback = function(err,resp,body){
  var json = JSON.parse(body)
  var transcript = ""
  for (var item of json.monologues){
    for (var element of item.elements){
      transcript += element.value
    }
  }
  console.log("TRANSCRIPT: " + transcript)
}
client.getTranscription(body.id, callback)

Use POST request

// Transcribe an audio file from local storage
var params = {
  media: "sample1.mp3",
  metadata: "This is a sample file from local storage"
}
client.post('jobs', params, function(err,resp,body){
  console.log(body)
})

// Transcribe an audio file from url
var params = {
  media_url: "http://www.somewhere.com/audio.mp3",
  metadata: "This is a sample file from a remote url"
}
client.post('jobs', params, function(err,resp,body){
  console.log(body)
})

Use GET request

// Get account info
client.get("account", {}, function(err,resp,body){
  console.log(body)
})

// Get a transcription job by job ID
var jobId=12261294
var query = 'jobs/' + jobId
client.get(query, {}, function(err,resp,body){
  console.log(body.status)
  console.log(body.id)
  console.log(body.completed_on)
})

// Get transcription jobs
var params = {
  limit: 2
}
client.get(params, function(err,res,body){
  for (var job of body){
    console.log(job.status)
    console.log(job.id)
    console.log(job.completed_on)
  }
})

// Get get transcription
var jobId=12261294
var query = 'jobs/' + jobId +"/transcript"
client.get(query, "", function(err,resp,body){
  if (!err){
    var json = JSON.parse(body)
    var transcript = ""
    for (var item of json.monologues){
      for (var element of item.elements){
        transcript += element.value
      }
    }
    console.log("TRANSCRIPT: " + transcript)
  }
})