How do I run speech recognizer before all other tasks in Java, in such a way that only if the output contains...












0















I have a login page and a sign up page in my program.
I want to run it only if the user says begin.
These pages are called in the main method of my class, and I have a speech recognizer class.
I want the program to continue only when String output.contains("begin") == true



I tried putting the Class.main(args) in my if(output.contains("begin") == true)) case, there was an unhandled exception, and when i surrounded that section with try and catch, it didn't work.



I was told that Inheriting and implementing the classes from my API will work, but I'm not quite sure how to do it.



final Microphone mic = new Microphone(FLACFileWriter.FLAC);
GSpeechDuplex duplex = new GSpeechDuplex("AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw");
duplex.setLanguage("en");
duplex.addResponseListener(new GSpeechResponseListener() {
String old_text = "";

public void onResponse(GoogleResponse gr) {
String output = gr.getResponse();
if (gr.getResponse() == null) {
this.old_text = response.getText();
if (this.old_text.contains("(")) {
this.old_text = this.old_text.substring(0,
this.old_text.indexOf('('));
}
System.out.println("Paragraph Line Added");
this.old_text = ( response.getText() + "n" );
this.old_text = this.old_text.replace(")", "").replace("( ", "");
response.setText(this.old_text);

}
if (output.contains("(")) {
output = output.substring(0, output.indexOf('('));
}
if (!gr.getOtherPossibleResponses().isEmpty()) {
output = output + " (" + (String)
gr.getOtherPossibleResponses().get(0) + ")";
}
response.setText("");
response.append(this.old_text);
response.append(output);

System.out.println(output);

if(output.contains("begin") == true){
duplex.stopSpeechRecognition();
mic.close();
Trying_Different_Languages t = new Trying_Different_Languages();
frame.dispose();
}
}
});


Expect The program to begin when i say begin but
It it doesn't begin when I say begin.
The try and catch statements just help in error free compilation.










share|improve this question

























  • That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

    – Anirudh Lakhotia
    Dec 30 '18 at 17:20


















0















I have a login page and a sign up page in my program.
I want to run it only if the user says begin.
These pages are called in the main method of my class, and I have a speech recognizer class.
I want the program to continue only when String output.contains("begin") == true



I tried putting the Class.main(args) in my if(output.contains("begin") == true)) case, there was an unhandled exception, and when i surrounded that section with try and catch, it didn't work.



I was told that Inheriting and implementing the classes from my API will work, but I'm not quite sure how to do it.



final Microphone mic = new Microphone(FLACFileWriter.FLAC);
GSpeechDuplex duplex = new GSpeechDuplex("AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw");
duplex.setLanguage("en");
duplex.addResponseListener(new GSpeechResponseListener() {
String old_text = "";

public void onResponse(GoogleResponse gr) {
String output = gr.getResponse();
if (gr.getResponse() == null) {
this.old_text = response.getText();
if (this.old_text.contains("(")) {
this.old_text = this.old_text.substring(0,
this.old_text.indexOf('('));
}
System.out.println("Paragraph Line Added");
this.old_text = ( response.getText() + "n" );
this.old_text = this.old_text.replace(")", "").replace("( ", "");
response.setText(this.old_text);

}
if (output.contains("(")) {
output = output.substring(0, output.indexOf('('));
}
if (!gr.getOtherPossibleResponses().isEmpty()) {
output = output + " (" + (String)
gr.getOtherPossibleResponses().get(0) + ")";
}
response.setText("");
response.append(this.old_text);
response.append(output);

System.out.println(output);

if(output.contains("begin") == true){
duplex.stopSpeechRecognition();
mic.close();
Trying_Different_Languages t = new Trying_Different_Languages();
frame.dispose();
}
}
});


Expect The program to begin when i say begin but
It it doesn't begin when I say begin.
The try and catch statements just help in error free compilation.










share|improve this question

























  • That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

    – Anirudh Lakhotia
    Dec 30 '18 at 17:20
















0












0








0








I have a login page and a sign up page in my program.
I want to run it only if the user says begin.
These pages are called in the main method of my class, and I have a speech recognizer class.
I want the program to continue only when String output.contains("begin") == true



I tried putting the Class.main(args) in my if(output.contains("begin") == true)) case, there was an unhandled exception, and when i surrounded that section with try and catch, it didn't work.



I was told that Inheriting and implementing the classes from my API will work, but I'm not quite sure how to do it.



final Microphone mic = new Microphone(FLACFileWriter.FLAC);
GSpeechDuplex duplex = new GSpeechDuplex("AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw");
duplex.setLanguage("en");
duplex.addResponseListener(new GSpeechResponseListener() {
String old_text = "";

public void onResponse(GoogleResponse gr) {
String output = gr.getResponse();
if (gr.getResponse() == null) {
this.old_text = response.getText();
if (this.old_text.contains("(")) {
this.old_text = this.old_text.substring(0,
this.old_text.indexOf('('));
}
System.out.println("Paragraph Line Added");
this.old_text = ( response.getText() + "n" );
this.old_text = this.old_text.replace(")", "").replace("( ", "");
response.setText(this.old_text);

}
if (output.contains("(")) {
output = output.substring(0, output.indexOf('('));
}
if (!gr.getOtherPossibleResponses().isEmpty()) {
output = output + " (" + (String)
gr.getOtherPossibleResponses().get(0) + ")";
}
response.setText("");
response.append(this.old_text);
response.append(output);

System.out.println(output);

if(output.contains("begin") == true){
duplex.stopSpeechRecognition();
mic.close();
Trying_Different_Languages t = new Trying_Different_Languages();
frame.dispose();
}
}
});


Expect The program to begin when i say begin but
It it doesn't begin when I say begin.
The try and catch statements just help in error free compilation.










share|improve this question
















I have a login page and a sign up page in my program.
I want to run it only if the user says begin.
These pages are called in the main method of my class, and I have a speech recognizer class.
I want the program to continue only when String output.contains("begin") == true



I tried putting the Class.main(args) in my if(output.contains("begin") == true)) case, there was an unhandled exception, and when i surrounded that section with try and catch, it didn't work.



I was told that Inheriting and implementing the classes from my API will work, but I'm not quite sure how to do it.



final Microphone mic = new Microphone(FLACFileWriter.FLAC);
GSpeechDuplex duplex = new GSpeechDuplex("AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw");
duplex.setLanguage("en");
duplex.addResponseListener(new GSpeechResponseListener() {
String old_text = "";

public void onResponse(GoogleResponse gr) {
String output = gr.getResponse();
if (gr.getResponse() == null) {
this.old_text = response.getText();
if (this.old_text.contains("(")) {
this.old_text = this.old_text.substring(0,
this.old_text.indexOf('('));
}
System.out.println("Paragraph Line Added");
this.old_text = ( response.getText() + "n" );
this.old_text = this.old_text.replace(")", "").replace("( ", "");
response.setText(this.old_text);

}
if (output.contains("(")) {
output = output.substring(0, output.indexOf('('));
}
if (!gr.getOtherPossibleResponses().isEmpty()) {
output = output + " (" + (String)
gr.getOtherPossibleResponses().get(0) + ")";
}
response.setText("");
response.append(this.old_text);
response.append(output);

System.out.println(output);

if(output.contains("begin") == true){
duplex.stopSpeechRecognition();
mic.close();
Trying_Different_Languages t = new Trying_Different_Languages();
frame.dispose();
}
}
});


Expect The program to begin when i say begin but
It it doesn't begin when I say begin.
The try and catch statements just help in error free compilation.







java inheritance speech-recognition speech-to-text






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 30 '18 at 17:47









CodeMatrix

1,5851819




1,5851819










asked Dec 30 '18 at 17:07









Anirudh LakhotiaAnirudh Lakhotia

186




186













  • That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

    – Anirudh Lakhotia
    Dec 30 '18 at 17:20





















  • That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

    – Anirudh Lakhotia
    Dec 30 '18 at 17:20



















That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

– Anirudh Lakhotia
Dec 30 '18 at 17:20







That isn't my key.. it's one i found in a tutorial. @CodeMatrix. Am I violating any rules?

– Anirudh Lakhotia
Dec 30 '18 at 17:20














1 Answer
1






active

oldest

votes


















2














In a program there should exist only 1 public static void main(String args) method. That is the indicator which tells you there starts the program.



Instead of calling the main method you should add a different method which do the stuff you want at a specific point.



So in detail it can look like that:



public class SomeClass {
public static void someMethodName() {
//some stuff you want to execute
}
}


So and where you want to execute the code:



...
SomeClass.someMethodName(); //executes the stuff you want.


In this case it would work if you create different methods which do exactly that you need to do at a specific point.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979707%2fhow-do-i-run-speech-recognizer-before-all-other-tasks-in-java-in-such-a-way-tha%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    In a program there should exist only 1 public static void main(String args) method. That is the indicator which tells you there starts the program.



    Instead of calling the main method you should add a different method which do the stuff you want at a specific point.



    So in detail it can look like that:



    public class SomeClass {
    public static void someMethodName() {
    //some stuff you want to execute
    }
    }


    So and where you want to execute the code:



    ...
    SomeClass.someMethodName(); //executes the stuff you want.


    In this case it would work if you create different methods which do exactly that you need to do at a specific point.






    share|improve this answer




























      2














      In a program there should exist only 1 public static void main(String args) method. That is the indicator which tells you there starts the program.



      Instead of calling the main method you should add a different method which do the stuff you want at a specific point.



      So in detail it can look like that:



      public class SomeClass {
      public static void someMethodName() {
      //some stuff you want to execute
      }
      }


      So and where you want to execute the code:



      ...
      SomeClass.someMethodName(); //executes the stuff you want.


      In this case it would work if you create different methods which do exactly that you need to do at a specific point.






      share|improve this answer


























        2












        2








        2







        In a program there should exist only 1 public static void main(String args) method. That is the indicator which tells you there starts the program.



        Instead of calling the main method you should add a different method which do the stuff you want at a specific point.



        So in detail it can look like that:



        public class SomeClass {
        public static void someMethodName() {
        //some stuff you want to execute
        }
        }


        So and where you want to execute the code:



        ...
        SomeClass.someMethodName(); //executes the stuff you want.


        In this case it would work if you create different methods which do exactly that you need to do at a specific point.






        share|improve this answer













        In a program there should exist only 1 public static void main(String args) method. That is the indicator which tells you there starts the program.



        Instead of calling the main method you should add a different method which do the stuff you want at a specific point.



        So in detail it can look like that:



        public class SomeClass {
        public static void someMethodName() {
        //some stuff you want to execute
        }
        }


        So and where you want to execute the code:



        ...
        SomeClass.someMethodName(); //executes the stuff you want.


        In this case it would work if you create different methods which do exactly that you need to do at a specific point.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 18:59









        CodeMatrixCodeMatrix

        1,5851819




        1,5851819






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979707%2fhow-do-i-run-speech-recognizer-before-all-other-tasks-in-java-in-such-a-way-tha%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas