Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

corti

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

corti

Replace window.SpeechRecognition with a mock object and automate your tests

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92
increased by26.03%
Maintainers
1
Weekly downloads
 
Created
Source

Corti

Build Status Dependency Status

Corti is a drop in replacement for the browser's SpeechRecognition object. It mocks some of the behaviour of the native object to facilitate automated testing, and provides a number of extra methods beyond the spec to help testing.

For an example of using Corti to test a real project, check out SpeechKITT.

To easily use Speech Recognition in your own project, check out annyang.

Sample Test With Corti

// Patch the current environment with a mock Speech Recognition object
Corti.patch();

// Interact with the mock object, like you would with the real SpeechRecognition object
var recognition = new window.SpeechRecognition();
recognition.onstart = function() {console.log("I'm listening");};
recognition.addEventListener('result', function(sre) {
  console.log(sre.results.item(sre.resultIndex).item(0).transcript);
});
recognition.addEventListener('end', function() {console.log("Quiet");});
recognition.continuous = true;

// Use extra utility methods added to the mock object to assist with testing
expect(recognition.isStarted()).toBe(false);
recognition.start();
expect(recognition.isStarted()).toBe(true);
recognition.abort();
expect(recognition.isStarted()).toBe(false);

// Simulate speech recognition
recognition.addEventListener('result', mySpyFunction);
expect(mySpyFunction).not.toHaveBeenCalled();
recognition.say("Next time you want to stab me in the back, have the guts to do it to my face");
expect(mySpyFunction).toHaveBeenCalled();

Methods Mocked

  • start()
  • abort()
  • stop()
  • addEventListener()

Attributes Mocked

  • interimResults
  • lang
  • continuous
  • maxAlternatives
  • onstart
  • onend
  • onresult

Events Mocked

  • start
  • end
  • result

Event Objects Mocked

  • SpeechRecognitionEvent
  • SpeechRecognitionResultList
  • SpeechRecognitionResult
  • SpeechRecognitionAlternative

Extra Utility Methods Added To Object

  • isStarted()
  • say()

Author

Tal Ater: @TalAter

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 18 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc