Git Product home page Git Product logo

watbot's Introduction

WatBot - An Android ChatBot powered by IBM Watson

Build Status

WatBot is an IBM Watson powered ChatBot running on Android and using Watson Assistant service on IBM Cloud (an open standards, cloud platform for building, running, and managing apps and services).

Note: This app uses Watson Assistant V1 API

Coding the app on Android Studio

Android Studio is the Official IDE for Android. Android Studio provides the fastest tools for building apps on every type of Android device.

Clone the repo and import the code in Android Studio,

git clone https://github.com/VidyasagarMSC/WatBot.git

Creation of Watson Assistant service; Adding intents & entities ; Building your dialog

Check this blog post for step-by-step and up-to-date instructions.

Configure the App

To configure the App you need to get the Watson Assistant service's Password, URL and Workspace ID

  • In the MainActivity class locate the method named sendMessage(). On the Manage tab of the Assistant service you created, click Launch tool > Skills > Click the three vertical dots next to the Skill > View API Details > You can find the Workspace ID, Username and password. If you wish to use API Key directly read the TODO, uncomment the code and replace the Placeholder with the API Key value.

    You can find the API Key and URL on the Manage tab or under service credentials.

        Assistant assistantservice = new Assistant("2018-02-16");
         //If you like to use USERNAME AND PASSWORD
         //Your Username: "apikey", password: "<APIKEY_VALUE>"
         assistantservice.setUsernameAndPassword("apikey", "<API_KEY_VALUE>");
    
         //TODO: Uncomment this line if you want to use API KEY
         //assistantservice.setApiKey("<API_KEY_VALUE>");
    
         //Set endpoint which is the URL. Default value: https://gateway.watsonplatform.net/assistant/api
         assistantservice.setEndPoint("<ASSISTANT_URL>");
         InputData input = new InputData.Builder(inputmessage).build();
         //WORKSPACES are now SKILLS
         MessageOptions options = new MessageOptions.Builder().workspaceId("<WORKSPACE_ID>").input(input).context(context).build();
         MessageResponse response = assistantservice.message(options).execute();
    

Add the `password` in the following code,

    assistantservice.setUsernameAndPassword("apikey", "<ASSISTANT_PASSWORD>");
  • Next is to get the Workspace ID.

Get the Workspace ID: and add it in the below code,

   MessageOptions options = new MessageOptions.Builder("<Workspace_ID>").input(input).context(context).build();

Gradle Entry

compile 'com.ibm.watson.developer_cloud:assistant:6.11.0'
  • Build and Run your app.

Enable Text to Speech

  • Create a Watson Text to Speech(TTS) service on IBM Cloud
  • Navigate to Service Credentials tab and click on "View Credentials".

On Line 95 of MainActivity.java, replace the password and URL placeholders with the TTS service credentials

    textService.setUsernameAndPassword("apikey", "<TEXT_TO_SPEECH_APIKEY>");
    textService.setEndPoint("<TEXT_TO_SPEECH_URL>");
  • Build and Run your app.

Now when you TAP on any message, the text will be heard via a Voice (Voice.EN_US_LISAVOICE). You can change the voice formats in the code (Line 120 0f MainActivity.java)

Note: The required gradle entries for TTS is already included in the build.gradle file

  compile 'com.ibm.watson.developer_cloud:text-to-speech:6.11.0'
  compile 'com.ibm.watson.developer_cloud:android-sdk:0.5.0'

Enable Speech to Text

  • Create a Watson Speech-To-Text (STT) service on IBM Cloud
  • Navigate to Service Credentials tab and click on "View Credentials".
  • Update lines 274-276 with the credentials.
  • Build and Run your app.

Note: The required gradle entries for STT is already included in the build.gradle file

     compile 'com.ibm.watson.developer_cloud:speech-to-text:6.11.0'
     compile 'com.ibm.watson.developer_cloud:android-sdk:0.5.0'

Chat with your own WatBot

If you have followed all the above instructions, you should be happily chatting with your Wat(son)Bot.

** Remember your bot will be talking to your Watson Assistant service (Intents, Entities and Dialog).**

Additional

Speaker labels

Note: The speaker labels feature is beta functionality that is available for US English, Japanese, and Spanish.

Speaker labels identify which individuals spoke which words in a multi-participant exchange. (Labeling who spoke and when is sometimes referred to as speaker diarization.) You can use the information to develop a person-by-person transcript of an audio stream, such as contact to a call center. Or you can use it to animate an exchange with a conversational robot or avatar. For best performance, use audio that is at least a minute long.

To enable, Click TODO on the bottom tab of Android Studio or search for TODO in MainActivity.java file and uncomment the lines. You should see the output in the logcat as shown below

SPEECHRESULTS: {
      "confidence": 0.5,
      "final": false,
      "from": 1.59,
      "speaker": 0,
      "to": 1.82
    }

Don't stop here!!! Keep coding and using IBM Cloud

watbot's People

Contributors

vidyasagarmsc 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

watbot's Issues

Problem with child nodes

Hello, I have a trouble with child nodes. I have this situation: Bot: Hello; Me: Hello ; Bot: You are welcome to my bot! Bot: What would you like to recommend?
So after You are welcome to my bot! I want to skip the user input and respond with What would you like to recommend? This is happening in "try it out" but not in my android App.. Have you any idea how could I resolve it ? I am using your java code for this app

Thanks a lot!

app closed when I pressed mic button

E/AudioRecord: Could not get audio input for session 81, record source 1, sample rate 16000, format 0x1, channel mask 0x10, flags 0
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -22.
E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.

                         --------- beginning of crash

E/AndroidRuntime: FATAL EXCEPTION: Thread-5
Process: com.example.vmac.chatbot, PID: 2468
java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.media.AudioRecord.startRecording(AudioRecord.java:976)
at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneCaptureThread.run(MicrophoneCaptureThread.java:63)
W/System.err: java.lang.RuntimeException: Session timed out, no data received in the last 30 seconds.
W/System.err: at com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.WebSocketManager$SpeechToTextWebSocketListener.onMessage(WebSocketManager.java:140)
W/System.err: at okhttp3.internal.ws.RealWebSocket$1.onMessage(RealWebSocket.java:62)
W/System.err: at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:242)
W/System.err: at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:108)
W/System.err: at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97)
W/System.err: at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152)
W/System.err: at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41)
W/System.err: at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97)
W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)
W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:761)

Errors

App crashing and not working

Send Data from Android to BlueMix

Hi,
Your Code is very useful to create a bot application, thanks for sharing.
Am unable to find a way to send the data from Android Application to Blue Mix server.

How am trying to send the value from android application.


private void sendMessage() {

        final String inputmessage = this.inputMessage.getText().toString().trim();
        if (!this.initialRequest) {
            Message inputMessage = new Message();
            inputMessage.setMessage(inputmessage);
            inputMessage.setId("1");
//Trying to set values for context here
            inputMessage.setFines("999");
            messageArrayList.add(inputMessage);
        } else {
            Message inputMessage = new Message();
            inputMessage.setMessage(inputmessage);
            inputMessage.setId("100");

            this.initialRequest = false;
            Toast.makeText(getApplicationContext(), "Tap on the message for Voice", Toast.LENGTH_LONG).show();

        }

        this.inputMessage.setText("");

        mAdapter.notifyDataSetChanged();

        Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_02_03);
                    service.setUsernameAndPassword("senate", "password");

                    context.put("1",inputmessage);

                    MessageRequest newMessage = new MessageRequest.Builder().inputText(inputmessage).context(context).build();

                    MessageResponse response = service.message("workspace", newMessage).execute();

                    //Passing Context of last conversation
                    if (response.getContext() != null) {
                        context = response.getContext();
                    }
                    Message outMessage = new Message();
                    if (response != null) {
                        if (response.getOutput() != null && response.getOutput().containsKey("text")) {
                            ArrayList responseList = (ArrayList) response.getOutput().get("text");
                            Log.i("responseList", responseList.get(0).toString());
                            if (null != responseList && responseList.size() > 0) {
                                outMessage.setMessage((String) responseList.get(0));
                                context = response.getContext();
//Trying to set values for context here
                                outMessage.setFines("200");
                                outMessage.setId("2");
                            }
                            messageArrayList.add(outMessage);
                        }

                        runOnUiThread(new Runnable() {
                            public void run() {
                                mAdapter.notifyDataSetChanged();
                                if (mAdapter.getItemCount() > 1) {
                                    recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, mAdapter.getItemCount() - 1);
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }


I want evaluate this reply using $var in Blue Mix conversation and respond accordingly.

java.lang.NullPointerException?

When I try your speakerlabels this is the error that I encounter and the speaker labels is not consistent
please help me solving this please
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
2019-02-26 19:29:40.316 21670-21670/com.example.ezminute W/System.err: at com.example.ezminute.activities.SpeakerLabelsDiarization$RecoTokens.cleanFinal(SpeakerLabelsDiarization.java:195)
2019-02-26 19:29:40.317 21670-21670/com.example.ezminute W/System.err: at com.example.ezminute.activities.SpeakerLabelsDiarization$RecoTokens.add(SpeakerLabelsDiarization.java:159)
2019-02-26 19:29:40.317 21670-21670/com.example.ezminute W/System.err: at com.example.ezminute.activities.SpeakerLabelsDiarization$RecoTokens.add(SpeakerLabelsDiarization.java:122)
2019-02-26 19:29:40.317 21670-21670/com.example.ezminute W/System.err: at com.example.ezminute.activities.convert_to_text$MicrophoneRecognizeDelegate.onTranscription(convert_to_text.java:482)
2019-02-26 19:29:40.318 21670-21670/com.example.ezminute W/System.err: at com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.SpeechToTextWebSocketListener.onMessage(SpeechToTextWebSocketListener.java:133)
2019-02-26 19:29:40.318 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.java:322)
2019-02-26 19:29:40.319 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:219)
2019-02-26 19:29:40.319 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:105)
2019-02-26 19:29:40.320 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
2019-02-26 19:29:40.321 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:213)
2019-02-26 19:29:40.322 21670-21670/com.example.ezminute W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
2019-02-26 19:29:40.322 21670-21670/com.example.ezminute W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
2019-02-26 19:29:40.322 21670-21670/com.example.ezminute W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2019-02-26 19:29:40.323 21670-21670/com.example.ezminute W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2019-02-26 19:29:40.323 21670-21670/com.example.ezminute W/System.err: at java.lang.Thread.run(Thread.java:764)

Getting Error Gradle Entry compile 'com.ibm.watson.developer_cloud:conversation:3.8.0'

Error:FAILURE: Build failed with an exception. * What went wrong: Task 'compile' is ambiguous in root project 'WatBot-master'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestShaders', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugShaders', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources', 'compileLint', 'compileReleaseAidl', 'compileReleaseJavaWithJavac', 'compileReleaseNdk', 'compileReleaseRenderscript', 'compileReleaseShaders', 'compileReleaseSources', 'compileReleaseUnitTestJavaWithJavac', 'compileReleaseUnitTestSources'. * Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Apk installation taking too long time

Hello Sir,

During the Gradle build, I got two error
Watson.iml could not be loaded and app.iml not loaded.

After gradle build finished , apk is taking too long time to install in virtual device.

Please help on that.

Watson not communicating

Hello, firstly thank you for your app.
When I "Run" app to my phone, I open it and bot does not welcome me nor answers my questions. Have you ran into that kind of problem? I just edited the credentials.

cant get response of any node

When i change And Finally to Skip user input.
i dont get the text from another which i set after skip user input
while it is working in Try section of website but not working in app

IllegalArgumentException: Unknown pattern character 'X'

when i am running this i am getting below error:
IllegalArgumentException: Unknown pattern character 'X'

at invoking TextToSpeech() constructor.

Can you please help here ??

when i am adding this it resolves the issue :

compile ('com.ibm.watson.developer_cloud:java-wrapper:1.1.1')

but introduces another conflict:

duplicate entry with an class file.

any help would be appreciated

Which build.gradle to update to enable Watson services?

This is a question. This github page says, "The required gradle entries for TTS is already included in the build.gradle file". I have checked two places(under WatBot and WatBot/app), but none of them contained the instructed stanza. Which file and which line do I need to update to enable Watson TTS & STT?

compile 'com.ibm.watson.developer_cloud:text-to-speech:6.11.0'
compile 'com.ibm.watson.developer_cloud:android-sdk:0.5.0'

Context isnt working

When i try the Conversation workspace in bluemix the response are working well, but when i try from app it doesnt seem to respond like the watson conversation does, i have set the context variables in my Child dialogs in Watson conversation service , and this code doesnt seem to send back context's.

When i try to add context in MessageOptions Builder it says Map cannot be converted to Context.

Any Idea ?

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.