Giter Club home page Giter Club logo

voice-elements's Introduction

Published on Vaadin  Directory Stars on vaadin.com/directory

<voice-elements>

Web Component wrapper to the Web Speech API, that allows you to do voice recognition (speech to text) and speech synthesis (text to speech) using Polymer.

Demo

Check it live!

Install

Install the component using Bower:

$ bower install voice-elements --save

Or download as ZIP.

Usage

  1. Import Web Components' polyfill:

    <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
  2. Import Custom Element:

    <link rel="import" href="bower_components/voice-elements/dist/voice-player.html">
    <link rel="import" href="bower_components/voice-elements/dist/voice-recognition.html">
  3. Start using it!

    <voice-player></voice-player>
    <voice-recognition></voice-recognition>

<voice-player>

Provides you a simple DOM API to do speech synthesis (text to speech).

Options

Attribute Options Default Description
autoplay boolean false Specifies if the audio should play when page loads.
accent en-US, en-GB, es-ES, fr-FR, it-IT, de-DE, ja-JP, ko-KR, zh-CN en-US Specifies the language to be synthesized and spoken.
text string You are awesome Specifies the text to be synthesized and spoken.

Methods

Method Parameters Returns Description
speak() None. Nothing. Triggers the voice audio to be played.
cancel() None. Nothing. Triggers the voice audio to be canceled.
pause() None. Nothing. Triggers the voice audio to be paused.
resume() None. Nothing. Triggers the voice audio to be resumed.

Events

Event Description
onstart Triggers when the voice begun to be spoken.
onend Triggers when the voice completed to be spoken.
onerror Triggers when the voice player detects an error.
onpause Triggers when the voice player is resumed.
onresume Triggers when the voice player is resumed.

<voice-recognition>

Provides you a simple DOM API to do voice recognition (speech to text).

Options

Attribute Options Default Description
continuous boolean true Specifies if the recognition should continue when the user pauses while speaking.
text string Returns the recognized text.

Methods

Method Parameters Returns Description
start() None. Nothing. Starts the voice recognition.
stop() None. Nothing. Requests to recognition service to stop listening to more audio.
abort() None. Nothing. Requests to immediately stop listening and stop recognizing.

Events

Event Description
onstart Triggers when the recognition begins.
onerror Triggers when there's a recognition error.
onend Triggers when the recognition ends.
onresult Triggers when there's a recognition result.

Browser Support

Unfortunately, the Web Speech API still have a poor support. Check Can I Use for more information.

IE Chrome Firefox Opera Safari
None ✘ Latest ✔ None ✘ None ✘ Latest (<voice-player> only) ✔

Development

In order to run it locally you'll need to fetch some dependencies and a basic server setup.

  1. Install Bower & Grunt:

    $ [sudo] npm install -g bower grunt-cli
  2. Install local dependencies:

    $ bower install && npm install
  3. To test your project, start the development server and open http://localhost:8000.

    $ grunt server
  4. To build the distribution files before releasing a new version.

    $ grunt build
  5. To provide a live demo, send everything to gh-pages branch.

    $ grunt deploy

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

For detailed changelog, check Releases.

License

MIT License © Zeno Rocha

voice-elements's People

Contributors

binbalenci avatar cesarwbr avatar che-effe avatar ecwyne avatar grifotv avatar heldr avatar masonlouchart avatar nixxxon avatar tekacs avatar zenorocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

voice-elements's Issues

I wrote a blog introducing your component

Hey zenorocha, super great element I have there. In fact, I wrote a blog introducing your component solely on Vaadin blog platform. You can check it out -> https://vaadin.com/blog/a-voice-component-for-your-next-web-app

We were having a blast while testing this element, especially when I start to put those tongue twisters sentences in different languages and let the element speak.

It would be really cool if the original author can drop a comment down below in the blog comment section, or in this tweet if you prefer something quicker.

Cheers!

[question] voice-recognition: is for-loop on results required?

There is 2 questions I would like to ask about this snippet.

for (var i = e.resultIndex; i < e.results.length; ++i) {
that.text = e.results[i][0].transcript;
e.result = that.text;
}

Why the voice-recognition element is working?

Due to the prefix increment of i in the for-loop, I expect a TypeError because cannot read "0" of undefined no matter is the array length. I added a log and the i variable seems incremented after a loop.

capture d ecran 2017-12-07 a 14 42 02

Do we need a for-loop?

I think what we need is simply read the last entry of the results array. AFAIK, the resultIndex variable is the index of the last result received. So the for-loop do 1 loop on the last entry right?

Thanks to help me to understand how it's working. 👨‍🎓

change accent not working

When i try to change the accent atributte, simply doesnt work!, and i have no bad code because in the voice-element page in "me gusta la gasolina" example dont change the accent.
My personal computer is in spanish, and the accent sound in spanish, but at work, (deutsch computer) sounds in english accent,I try to change accent in but nothing change

voice-player crashes when text length > 306

hi, I think this is awesome that you have implemented voice-elements. I got to hear the presentation at JS.LA a while back. I am testing the voice-player out for a class project and it is crashing when I try to play a string > about 306 or 308 characters.
after the crash, even if I refresh my browser, the voicePlayer.speak() function does not recover. if I restart my webserver, the speak() function will recover. I don't know where to search for error messages. thanks.
(Chrome 44.0 on Mac OSX 10.10.4)

Polymer 0.4.0

bower.json

"dependencies": {"polymer": "Polymer/polymer#~0.3.1"}

I have tested with 0.4.0 and voice-elements still works. This limitation prevents users from using 0.4.0.

"dependencies": {"polymer": "Polymer/polymer>=0.3.1"}

Will correct this.

voice-player crash the all app in firefox and all unsupported browsers

In firefox, the code below throw a TypeError : this.speech is undefined

textChanged: function() {
                this.speech.text = this.text;
},

Some controls should be welcome in order to don't crash all app when this.speech is not initialize in created function.
like

textChanged: function() {
    if ( this.speech) {
                this.speech.text = this.text;
   }
},

<voice-elements> not working on Topeka-based app

Hi everyone,

I'm having some trouble implementing in my Polymer app. It's based on Polymer's quiz demo app and I'm trying to use the voice recognition element to submit answers. This is my code:

<link rel="import" href="../quiz-base.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="import" href="../../voice-elements/voice-player.html">
<link rel="import" href="../../voice-elements/voice-recognition.html">

<polymer-element name="quiz-voice-recognition" extends="quiz-base">
<template>

<style>  
:host {
padding: 40px;
}

:host-context(.wide) {
width: 304px;
margin: 0 auto;
}

paper-input {
width: 100%;
height: 48px;
}

core-icon[icon="av:mic"] {
width: 120px;
height: 120px;
}  
 </style>

<div>{{quiz.start}}</div>

<voice-recognition id="recognition-element"></voice-recognition>

<script>
var form = document.querySelector('#recognition-form'),
input = document.querySelector('#recognition-input'),
element = document.querySelector('#recognition-element');
form.addEventListener('submit', function(e) {
e.preventDefault();
element.start();
});
element.addEventListener('result', function(e) {
input.textContent = e.detail.result;
});
</script>

<form id="recognition-form">
<fieldset>
<textarea id="recognition-input" readonly=""></textarea>
</fieldset>
<fieldset>
<button id="recognition-submit">Start!</button>
</fieldset>
</form>

<div>{{quiz.end}}</div>
</template>

<script>
Polymer('quiz-voice-recognition', {

eventDelegates: {
'input': 'answered'
},

isCorrect: function() {
return this.areEqual(this.value, this.quiz.answer);
},

areEqual: function(s1, s2) {
return s1 && s2 && s1.trim().toLowerCase() === s2.trim().toLowerCase();
}

});
</script>
</polymer-element>

Everytime I load the page I get the following error and when clicking the submit button it doesn't trigger the authorization popup to enable voice recognition as seen in the demo site: Uncaught TypeError: Cannot read property 'addEventListener' of null

Pronunciation training and assessment

Hello
I am making text Pronunciation web application for language learning.
if i use "voice-elements" can i check user Pronunciation. When user read some text, sentence or word
application give score for user Pronunciation.

How about Pronunciation training and assessment in "voice-elements" ?

How to get Project when input is also project

I am having one word being pronounced as a similar word. I would like to know how to make the input word "project" to be defined as a works in the making or as in a media "project".

Add <a-voice> </a-voice> element - For voice control

This idea is intended to optimize web browsing on AR-like devices such as Google Glass. However it could just as easily be used on phones.

End Goal:

               <a-voice ph="fuh-net-ik" href="...">phonetic name</a-voice>

ph = phonetic attribute -> could be used to optimize voice based search engines later

Anyhow thanks @zenorocha for suggesting I post this as an "issue" lol

voice dictation - control words ?

Is there the ability to script these in ?
For example "full stop" or "new paragraph" or "delete"

I tried "full stop" and it worked. But its not in your code, so its part of the google code ?

I woudl like to extend at the script level so that when a control word is said, i can react

Android, Firefox OS, WinPhone e Ios

I want to first congratulate the project is truly splendid.

I would be pergutar is compatible with android or other mobile OS. I could just use google chrome.

voice-recognition: Mobile phone stops listening even with the "continuous" attribute

On my app, I have a button to start and stop voice recognition.

voice-recognition-button
("Parlez" = "Speak now")

The purpose is simply to fill an input form. On browser everything is working well. The user starts and stops the audio capture when they wants.

On my Nexus 5, the mobile phone itself stops the capture. Moreover, the end event is not thrown and the result event is twice. As the app is waiting for end event to update the button style, it's never updated.

Current behaviors

  • mobile phone stops the audio capture even when continuous attribute is true
  • result event is fired twice when mobile phone stops the capture

Expected behaviors

  • mobile phone records the voice continuously when continuous attribute is true
  • result event fired only once

Nexus 5
Android 6.0.1
Chrome mobile
Polymer 1.9.1

voice-recognition Element does not clear it's previous result, on a new run

Hi, I am having a pestering problem where the last result get's appended to the current result, the more times I trigger the element, the way I solved this was by keeping a track of how long the last e.detail.result was and accordingly substring out that length from the next result, but this is a sure shot way of creating memory leaks, or unnecessary computation.

Is it possible to clear the internal results after a on-result is triggered. Thanks.

Polymer 2.0 support

This is an awesome element, Just curios to know if you guys are going to upgrade it in Polymer 2.0?

How to handle non supported characters?

It seems in the demo, when I insert certain characters (such as a number with a decimal like "59.1") The demo breaks and nothing on the page will function until I completely close and re-open chrome. Is there anything error handling or checking for not supported characters? Is this something to take up with the polymer component, if so where does that live?

This is amazing, I think it will be huge for web accessibility.

voice-player autoplay don't speach when textChange

Bug 1 : The event textChanged should play the new text in autoplay=true mode.
The solution is something like that (int voice-player)

 textChanged: function() {
                this.speech.text = this.text;
                if (this.autoplay) {
                    this.speak();
                }
            },

Bug 2 : In autoplay=false, is not possible to call speach function with the current text
Each time it play the old one, because the event textChanged, arrive after the speachTextChanged
like this sample

  <template>
     <core-input inputValue="{{searchText}}"></core-input>
    <paper-icon-button icon="search" on-tap="{{speachButtonHanlder}}"></paper-icon-button>
     <voice-player id="search_notif_vocal" text="{{speachText}}" accent="en-US" autoplay="true"></voice-player>
  </template>
  <script>
       ...
            speachButtonHanlder : function (e) {
               this.$.search_notif_vocal.setAttribute("text", this. speachText);
                this.$.search_notif_vocal.speak();
            },
       ...
  </script>

This code play all the time the old Text.

voice-player speak crashes in Chrome for multiple calls

I realize that when I make a speak() call when another audio is playing it doesn't work anymore. If I reload the page it works again until I call speak twice and I don't wait for the audio to stop.

Probably it is a Web Speech API problem.

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.