Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor II
33 Views

Android speech to text

Jump to solution

Dear friends,

My name is Alex Hang, i am 16 years old, and i'm from Bucharest, Romania. I am trying to build an Android app using Intel XDK for an international programming contest. Intel XDK really helps me and makes everything easier, but i have one single problem: i want to introduce a speech to text feature in the app, but everithing I tried doesn't works. Can you help me ?

Alex

Tags (2)
0 Kudos

Accepted Solutions
Highlighted
Valued Contributor I
33 Views

Hello. I am using the plugin org.apache.cordova.speech.speechrecognition from Cordova Repository. It is working good. Android is easier. iOS you need an account (see in documentation).

You can see this plugin working in "Fale para Bate-Papo" (Speak to Chat), Android and iOS.

View solution in original post

0 Kudos
21 Replies
Highlighted
Valued Contributor I
34 Views

Hello. I am using the plugin org.apache.cordova.speech.speechrecognition from Cordova Repository. It is working good. Android is easier. iOS you need an account (see in documentation).

You can see this plugin working in "Fale para Bate-Papo" (Speak to Chat), Android and iOS.

View solution in original post

0 Kudos
Highlighted
New Contributor II
33 Views

Thank you Sir, your help was precious for me. I tried it and it worked properly.

                                                                  Alex Hang

0 Kudos
Highlighted
Employee
33 Views
0 Kudos
Highlighted
New Contributor II
33 Views

Thanks for the help. Both examples are very useful and helped me a lot.

I used mister Hamilton Tenorio da Silva's example and I found this code sample:

<script type="text/javascript">
var recognition;
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
        if (event.results.length > 0) {
            q.value = event.results[0][0].transcript;
            q.form.submit();
        }
    }
}
</script>
<form>
    <input type="search" id="q" name="q" size=60>
    <input type="button" value="Click to Speak" onclick="recognition.start()">
</form>

It works really well but i need to memorize the word ( words) that I say in a variable so that I can use it later in the app.

I also found on the internet another very good Speech Recognition code sample, but I have the same problem: it doesn't memorize the word   (words) in a variable.This one requires this plugin: https://github.com/poiuytrez/SpeechRecognizer.git

        <script type="text/javascript">

            function onDeviceReady(){
                console.log("Device is ready");
            }

            function recognizeSpeech() {
                var maxMatches = 5;
                var promptString = "Speak now"; // optional
                var language = "en-US";                     // optional
                window.plugins.speechrecognizer.startRecognize(function(result){
                    alert(result);
                }, function(errorMessage){
                    console.log("Error message: " + errorMessage);
                }, maxMatches, promptString, language);
            }

            // Show the list of the supported languages
            function getSupportedLanguages() {
                window.plugins.speechrecognizer.getSupportedLanguages(function(languages){
                    // display the json array
                    alert(languages);
                }, function(error){
                    alert("Could not retrieve the supported languages : " + error);
                });
            }

            document.addEventListener("deviceready", onDeviceReady, true);
        </script>

        <button onclick="recognizeSpeech();">Start recognition</button>
        <button onclick="getSupportedLanguages();">Get Supported Languages</button>
    

 Can somebody help me to memorize the word( words) that I say in a variable? If somebody knows another code sample, it will be very helpful.

                                                                                                                                                                     Alex Hang

 

 

0 Kudos
Highlighted
Valued Contributor I
33 Views

@Alex> I dind´t know if I undertand your question. Do you need to save the words in a variable to use in another moment? 

You can save when you get the return (q.value = event.results[0][0].transcript;). The string can be used normally. Just save in a database or cookie.

 

0 Kudos
Highlighted
New Contributor II
33 Views

Thank you so much Sir, I would not have been able to finish this application without your help. The Speech to Text Method is working excellent. 

                                                                                                                                                      Alex Hang

0 Kudos
Highlighted
Valued Contributor I
33 Views

@Alex: great! Googd luck with the app.

0 Kudos
Highlighted
New Contributor II
33 Views

I have only one single problem.

I am also trying to introduce a text to speech feature in the app. It has the purpose to read the texts in the app. I tried to use this plugin https://github.com/domaemon/org.apache.cordova.plugin.tts  But when I try to make it "talk" using the below code sample ( I found it on the Internet), nothing happens. Can anyone help me with a different plugin and code sample or indicate me a code sample that works with this plugin ?

    
  window.plugins.tts.speak("Welcome to Discover Romania", win, fail);

 

                                                                                                                                               Alex Hang

0 Kudos
Highlighted
Valued Contributor I
33 Views

@Alex> I am using this same plugin. It works well in Android (iOS is not working, but I have no time to find the problem...).

As far as I remember, just change the code to "navigator.tts.speak("xxxx", ...".

0 Kudos
Highlighted
Beginner
33 Views

hi can anyone help me, how do i include the cordova speech recognition plugin into intel xdk 

0 Kudos
Highlighted
New Contributor II
33 Views

Hello Sir!

After you created a project, in order to introduce a plugin to your app you have to open the Projects tab. To do it you must click on the "Projects'' Button in the upper left corner of the screen. When the page is opened, click on the "+" near the text "Plugin Management". Then click on "Add Plugin to this project". On the left side of the window you will have a list. Select "Third Party Plugins". On the screen you will see in the upper part of the window a line where it says: "Plugin Source". Select the second option ("Git Repo"). Now in the Repo URL field you have to write this link  https://github.com/macdonst/SpeechRecognitionPlugin.git    

Now, Intel XDK will add the plugin to the project, and will show a succes message when everything is done.

This is how i did and it worked well. I hope this post will be useful.

                                                                                                                         Alex Hang                            

0 Kudos
Highlighted
Beginner
33 Views

the plugin work fine thanks for the help but i encounter a problem regard with the example given for the speech recognition.

How do i apply it on intel xdk, like how i apply the example in intel xdk because everytime i try to test it on app preview it cam out nothing 

0 Kudos
Highlighted
New Contributor II
33 Views

Try to build your app and test it directly on your device, by installing the apk file. I had the same problem, the speech recognition was not working on app preview, but when I built the app and installed it on my Android Device it worked perfectly.Just use the example given above. only the first example works with this plugin. The second example requires this plugin  http://https://github.com/poiuytrez/SpeechRecognizer.git

i tried them both and they work excellent !

I hope this comment was useful !

                                                                                                                                                        Alex Hang                                                                                                     

0 Kudos
Highlighted
Beginner
33 Views

okay im using plugin https://github.com/poiuytrez/SpeechRecognizer and do i need to include

SpeechRecognizer.startRecognize(success, error, maxMatches, promptString, language);
SpeechRecognizer.getSupportedLanguages(success, error);

or just use the full example code only 

 

0 Kudos
Highlighted
New Contributor II
33 Views

I only used the code sample from that post.

I tried it and it works excellent !

Just use this code and it will surely work.

        <script type="text/javascript">

            function onDeviceReady(){
                console.log("Device is ready");
            }

            function recognizeSpeech() {
                var maxMatches = 5;
                var promptString = "Speak now"; // optional
                var language = "en-US";                     // optional
                window.plugins.speechrecognizer.startRecognize(function(result){
                    alert(result);
                }, function(errorMessage){
                    console.log("Error message: " + errorMessage);
                }, maxMatches, promptString, language);
            }

            // Show the list of the supported languages
            function getSupportedLanguages() {
                window.plugins.speechrecognizer.getSupportedLanguages(function(languages){
                    // display the json array
                    alert(languages);
                }, function(error){
                    alert("Could not retrieve the supported languages : " + error);
                });
            }

            document.addEventListener("deviceready", onDeviceReady, true);
        </script>

        <button onclick="recognizeSpeech();">Start recognition</button>
        <button onclick="getSupportedLanguages();">Get Supported Languages</button>

 

 

 

                                                                                                                                                   Alex Hang

0 Kudos
Highlighted
Beginner
33 Views

Ops sorry i forgot to enable a voice speech input in my device no wonder it doesn't work.

Okay how do i make the voice speech input variable on a text box rather using an alert box 

0 Kudos
Highlighted
New Contributor II
33 Views

Hafiz Y, if you want to have the speech transcription in a text box, you can use the first example without changing anything. 

<script type="text/javascript">
var recognition;
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
    recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
        if (event.results.length > 0) {
            q.value = event.results[0][0].transcript;
            q.form.submit();
        }
    }
}
</script>
<form>
    <input type="search" id="q" name="q" size=60>
    <input type="button" value="Click to Speak" onclick="recognition.start()">
</form>

This is the code line that shows the transcript in the text box.

<input type="search" id="q" name="q" size=60>

You can adapt this code line for the second example if you want. Instead of "q", at the second example the variable that contains the transcript is "result". If you want the app not to show ant other alerts delete this code line from the second example.

alert(result);

I hope this post was useful !

                                                                                                                                                                    Alex Hang

0 Kudos
Highlighted
Beginner
33 Views

Hi Alex H.

I'm using the plugin from http://https://github.com/poiuytrez/SpeechRecognizer.git and I facing some problem which are TypeError: Cannot read property 'startRecognize' of undefined. Do you have this kind of problem?

Thanks.

0 Kudos
Highlighted
New Contributor II
33 Views
Hello Han Quan ! I have not experienced that issue untill now, but searching on the Internet I found a very interesting article that may help you. http://stackoverflow.com/questions/21258102/android-phonegap-speechrecognizer-issue-cannot-read-prop... The best answer on that forum is: "Did you launch phonegap build android after you add the plugin? When you install plugins, they are installed only in the /plugins folder of the project but not in the platform folder. You have to run phonegap build or phonegap prepare for any platform to have the plugin fully installed. And then after you can refresh the project in eclipse and you should see the java part of the plugin in the /src folder and the javascript in /assets/www/plugins If the folder platforms\android\assets\www\plugins... is not there after the build, that may be because your project got corrupted. In that case you can try to empty the plugins folder at the root of your project and re-install all plugins. If that's not enough, you can retry emptying both platforms and plugins folder (think to save any customisation you may have done in platforms folders) ." I hope that this post is useful for you! If there are other issues I can help you with, please feel free to ask. Alex Hang
0 Kudos