Giter Site home page Giter Site logo

Comments (11)

cdimascio avatar cdimascio commented on September 23, 2024 1

@AlanSutherland, awesome! glad to here you've got it sorted out. please let me know if there is something i can do to make the docs easier to understand. PRs are welcome as well. thanks

from watson-html5-speech-recognition.

cdimascio avatar cdimascio commented on September 23, 2024

@yuenghole
See the section Example. Follow those instructions to get the example running. Do this first to ensure you have everything working.

Once you do, you can do one of the following:
Note, given that I don't know how your app is structured, I'm going to provide a few possibilities

  1. simplest thing to do: Drop your Angular assets into the public folder of the example app you just set up. Once you do this, the example app will now serve your Angular app. Since the example is all setup for speech reco, you can simply call the speech api from your angular app.
    Here is an example of the call you would make from your angular app. Do this to initialize and state the token url and then use it like this

  2. If you have a backend server, then 1. isn't likely a viable option for you.
    If your backend is running node.js, include stt-token.js into it. Then see app.js to see how to include it as middleware.
    its one line of code
    app.use('/api/speech-to-text/', require('./stt-token.js'));
    You can use the example app as a template.

  3. if you have a backend server that is running something other than Node e.g. Java, Ruby, Pythong, ..., you either have to port this code to your language of choice or start the example server with CORS enabled (i can help with this if necessary - i haven't added cors support yet, but should be very easy. I'm happy to do it if you require it)

hope this helps

from watson-html5-speech-recognition.

yuenghole avatar yuenghole commented on September 23, 2024

Hi, @cdimascio.

Thank you for the reply.

I tried to include the speech.js as a library and I included the code below in my index.html and it is working:

<script src="scripts/speech.js"></script>
<script style="display: block;">
    var speech = SpeechToText;
    var activeSTT;

    function listen() {
        activeSTT = speech.listen({
            onStart: function() {
                console.log('onStart Speech event');
            },
            onResult: function(e) {
                console.log('onResult Speech event', e.text);
                document.getElementById("recognizedText").innerHTML = e.text;
                if (e.isFinal) {
                    stopListening();
                }
            },
            onError: function(e) {
                console.log('onError Speech event', e);
            },
            onEnd: function(e) {
                console.log('onEnd Speech event', e);
                stopListening();
            }
        });
    }

    function startListening() {
        if (activeSTT) {
            // do nothing, speech is active
        } else if (speech.isSupported) {
            listen();
        } else {
            alert('speech not supported by this browser');
        }
    }

    function stopListening() {
        if (activeSTT) {
            activeSTT.stop();
            activeSTT = null;
        }
    }

    document.querySelector('#button').onclick = startListening;

</script>

However, may I know if I have a token (
token.zip
), how do I change the speech.js or somewhere else to use this token?

Thanks

from watson-html5-speech-recognition.

yuenghole avatar yuenghole commented on September 23, 2024

Besides, this is the speech.js I am using
speech.zip

from watson-html5-speech-recognition.

cdimascio avatar cdimascio commented on September 23, 2024

@yuenghole the client lib itself will set the token for you. You just need to provide the endpoint to retrieve the token.
You can do that as follows:

var Speech = require('watson-html5-speech-recognition');
var speech = new Speech.SpeechToText({
  watsonTokenUrl: '/api/speech-to-text/token' // <-- endpoint to retrieve token. This endpoint will be POSTed to to obtain the token. This endpoint refers to the endpoint exposed by the example server
});

from watson-html5-speech-recognition.

cdimascio avatar cdimascio commented on September 23, 2024

no changes are required to speech.js

from watson-html5-speech-recognition.

pixelomo avatar pixelomo commented on September 23, 2024

This looks like exactly what I need for adding stt to my app, what would be nice is instead of having to set up the demo app and then try incorporate it in to my app or vice versa there were instructions on how to just use it like any other node module.

i.e.

const Speech = require('watson-html5-speech-recognition');
const speech = new Speech.SpeechToText({
  username: 'username',
  password: 'password',
});

or even better say within a react app

import Speech from ('watson-html5-speech-recognition');

class Chat extends React.Component{
    render() {
        return (
            <div className="chatBox" >
                <Speech username="username" password="password" ></Speech>
            </div>
        );
    }
}

from watson-html5-speech-recognition.

cdimascio avatar cdimascio commented on September 23, 2024

@AlanSutherland good point. The challenge here is that there is both a client and a server component, however perhaps I can consolidate it all onto the client and make the server configuration optional. This would make the basic setup very easy to get up and running and the more advanced case, well a bit more involved.
The basic setup would look fairly close to what you provided above
thoughts? suggestions?

from watson-html5-speech-recognition.

pixelomo avatar pixelomo commented on September 23, 2024

@cdimascio I'm actually pretty frustrated, I've been going around in circles with your documentation. All the examples for getting started with the SDK show how to get a token using curl. Which is fine I can do that, but that means once an hour I need to manually run a curl command on the terminal and update my code ...hardly ideal :/

At least I can see that using the method I can get STT working. Here's the code if anyones interested:

const WatsonSpeech = require('watson-speech');


stt() {
        var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7EyjeFR4Z%2BPnld12WWBBhDZbPefqwLEJqPfMaQ%3D',
            outputElement: '.output' // CSS selector or DOM Element
        });
        stream.on('error', function(err) {
            console.log(err);
        });

        if(document.querySelector('.active-mic')){
            stream.stop();
        } 
}

But I need an automatic way of generating a new token. All docs point to this example.

Here's my version of the example:

const watson = require('watson-developer-cloud');

const authorization = new watson.AuthorizationV1({
  username: 'user',
  password: 'pw',
  url: watson.SpeechToTextV1.URL
});

authorization.getToken(function (err, token) {
  if (!token) {
    console.log('error:', err);
  } else {
    console.log(token)
  }
});

when I run npm run build I get a number of errors, first one is:

ERROR in ./~/watson-developer-cloud/retrieve-and-rank/v1.js
Module not found: Error: Can't resolve 'fs'

It appears that the fs package has been removed from npm.

I found an interesting stackoverflow question related to this. Sadly it appears that the first answer uses request() which also relies on fs and the second answer on child_process which has also been removed from npm...

The second answer is interesting in that it shows a way to exec a curl command from javascript though.

I think the watson-developer-cloud package needs updating to remove the dependency for fs and/or the documentation needs updating.

from watson-html5-speech-recognition.

pixelomo avatar pixelomo commented on September 23, 2024

@cdimascio forgot to mention I'm using webpack

from watson-html5-speech-recognition.

pixelomo avatar pixelomo commented on September 23, 2024

I was trying to run this client-side, didn't realise it had to be server-side

from watson-html5-speech-recognition.

Related Issues (6)

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.