Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java code for speech to text

 
Glen Hynes
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all. the code below is used to convert speech to text on an android app. This code works when the speech button is pressed and whatever you say is transferred into text.
When the speech function closes, the the text is showing.
If you hit the speech button again, the previous text is cleared and the new text shows on the page.
Can anyone help me edit the code so that the previous texts remain on the page?


 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general strategy would be to get the previous text, append the new String to the old text, then add the text back to the TextView. It may be a little more complicated because you probably want to add a line break, and maybe other conditions (like a fixed number of lines to display, scrolling, or something.

An alternative to the TextView which may better match your goals might be to use a ListView. The ListView can be bound to an ArrayAdapter. Whenever you get a String you would add it to the ArrayAdapter, which would cause the ListView to expand to accommodate the new text. It makes it easier to control the values which get displayed (the number of lines, formatting, etc...)
 
Glen Hynes
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks. this sounds like exactly what i need. now to go and try write this into the code! i am a beginner with java so any help appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic