Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:40:46+00:00 2026-06-02T20:40:46+00:00

I am trying to convert speech to text and to display it on an

  • 0

I am trying to convert speech to text and to display it on an AWT textArea.
But the output in the speech to text converter function is generated inside a while loop and I am unable to display that on the textArea. I am getting a null pointer exception; please someone help.

public class Speechrec  {

    private static TextArea textArea;
    String resultText;
    private String dr;

    public void recognizer(String[] args) {

        try {
            URL url;
            if (args.length > 0) {
                url = new File(args[0]).toURI().toURL();
            } 
            else {
                url = Speechrec.class.getResource("speechrec.config.xml");
            }    
            System.out.println("Loading...");    
            ConfigurationManager cm = new ConfigurationManager(url);    
            Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
            Microphone microphone = (Microphone) cm.lookup("microphone");    
            /* allocate the resource necessary for the recognizer */
            recognizer.allocate();    
            /* the microphone will keep recording until the program exits */
            if (microphone.startRecording()) {    
            System.out.println("Say: some greetings");
            while (true) {
                System.out.println("Start speaking. Press Ctrl-C to quit.\n");

                Result result = recognizer.recognize();

                if (result != null) {
                    String resultText = result.getBestFinalResultNoFiller();            
                    textArea.setText(resultText);
                } 
                else {
                    System.out.println("I can't hear what you said.\n");
                }
            }
            } 
            else {
               System.out.println("Cannot start microphone.");
               recognizer.deallocate();
               System.exit(1);
            }
        } 
        catch (Exception) {                
            // exception handling
        }
    }        

public static void main( final String[] args) throws IOException {
    Speechrec sp1=new Speechrec();      
    Frame frame=new Frame("speech to sign language converter");
    TextArea textarea=new TextArea (05,30);     
    Button button = new Button("Start speaking"); 
    // ...        
    frame.add(button,BorderLayout.SOUTH); 
    // ...
    frame.setLayout(new FlowLayout(FlowLayout.TRAILING,50,15));
    frame.setSize(500,400); 
    frame.setVisible(true);

    button.addActionListener(new ActionListener() {           
         public void actionPerformed(ActionEvent e1) {      
             Speechrec sp=new Speechrec();
         sp.recognizer(args);
          }});
    }    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:40:47+00:00Added an answer on June 2, 2026 at 8:40 pm

    Declare your text area as a private static field in your class. Then you can access it in easily like textArea.setText("something");

    private static TextArea textArea;
    
    public static void main( final String[] args) throws IOException{
        Speechrec sp1 = new Speechrec();
        textArea = new TextArea(sp1.dr,05,30);
        Button button = new Button("Start speaking");
        // and so on...
    }
    
    while (true) {
    
            Result result = recognizer.recognize();
    
            if (result != null) {
    
                String resultText = result.getBestFinalResultNoFiller();
    
                dr = resultText;
    
                textArea.setText(resultText);
    
                // or:
    
                textArea.append(resultText);
            } 
    }
    

    In the next step you should move all code that creates your UI into the constructor of your class. That would be a cleaner solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to convert output from a rest_client GET to the characters that are represented
Trying to convert the following but am having difficulty. Can anyone see where I'm
Im trying to convert unixtime to date but the results im getting are wrong
I'm trying convert some decimals to varchar , but they are getting rounded .
Trying to convert some code, but for all my googling I can't figure out
Trying to convert a string to NSURL and this is not happening. barcodeTextLabel.text =
I'm using lambda expression and trying convert into uint while adding into the Hashset.
I´m trying to convert that: <% var obj = Model.Div; %> <script type=text/javascript> var
While trying to convert my structure to byte* : objNDSDriver.StartFn((byte*)objSTNDSFTPDriverInfo); I am getting the
I'm trying convert a bunch of pictures and videos, but when I convert it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.