-5

Just curious to know what it will take for me to have human capability to my java programs. Currently to display a message i use System.out.println and to read user's input i may use something like System.in. Wondering if there is a way for me to say System.out.speak() and System.hear();

If not possible with Java i'm okay to learn other languages please help.

user1501382
  • 1,187
  • 14
  • 18
  • your question is not clear.. maybe you mean voice recognition and text to speech..? you may begin from googling and reading some tutorials.. – Yohanes Khosiawan 许先汉 Mar 25 '14 at 03:13
  • I looked at voice recognition software but those read which is in a text editor. What i want to do is, when i have to error out or print something i want system to speak instead of printing test on screen. Similarly when i need user input, i expect user to say instead of typing his option. – user1501382 Mar 25 '14 at 03:22
  • 1
    I *want* [Truth, Justice, Freedom, Reasonably Priced Love, and a Hard-Boiled Egg](http://wiki.lspace.org/mediawiki/index.php/Glorious_Revolution)! – Elliott Frisch Mar 25 '14 at 03:27
  • May i know why i have -5 score. It does not really matter but would like to learn. – user1501382 Mar 26 '14 at 02:46

2 Answers2

2

Wondering if there is a way for me to say System.out.speak() and System.hear();

Literally, no.

  1. System.out is a PrintWriter and there is no speak() method.
  2. There is no System.hear() method.
  3. Adding such methods would entail hacking on standard system classes ... making the resulting library "NOT Java(tm)".

Furthermore, there are no standard APIs in the Java libraries for text to speech or speech to text. (And I'm not aware of any other language that offers this functionality as a standard feature.)

However, I'm sure that if you looked hard enough you could find 3rd-party tools for doing this that could be integrated with Java, one way or another.

UPDATE

In fact, you have found the standard Android (as distinct from Java) APIs for this:


From a design perspective, I think it would be a better idea to support this kind of thing in the OS's user interface framework (where the user can control it), and not embed it in individual applications.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 1
    Thank you Stephen for the direction. I'm not an expert programmer to modify system class. I googled and this is the nearest i could reach to use something pre-build/tested. Though this is not native to Java and may be specific to Android developers [link] (http://developer.android.com/reference/android/speech/package-summary.html) – user1501382 Mar 25 '14 at 05:50
0

So it sounds like this is what you want:

"System.out.speak()" -- as you know by now, that's not a real thing. I think I could propose a high-level, temporary solution.

It sounds like you just want to be audibly notified when you reach a certain part in your code. Perhaps you could just record a wav or mp3 of yourself saying whatever it is you want to hear as an alert, and then import the wav/mp3 into your project directory. Refer to this article to figure out how to playback that audio: Playing .mp3 and .wav in Java?

You could simply make a static method that takes in a string representing the desired audio playback and then does so by however the link above suggests.

If you want it to take in a string, and then have some sort of computer voice (e.g. Microsoft Sam) speak that string, that's a lot more complicated. I have no idea how to do that haha. But I'm guessing it's not as hard as your idea of "System.in.hear()"

"System.in.hear()" -- This is definitely not a thing. This requires knowledge in the field of Speech-To-Text (STT). This is basically how Siri or Google Now parses what you say to them. I'm sure there are libraries you could find that do this, but I'm too lazy to look for you :(

I hope this helps a little bit. I'm doing a little bit of research right now on STT and I saw your question pop up. I'm not very knowledgeable in the area, but I hope you figure out a way to get audio feedback instead of having to put println's everywhere. You should figure that out and reuse it.

Happy programming!

Community
  • 1
  • 1
FateNuller
  • 878
  • 2
  • 12
  • 27