1

I have got this Voice Recording code from CodeNameOne's official website, here's the code.

({https://pastebin.com/FsLmMK2b})

When I record my voice for the 1st time, everything seems fine and I can hear a playback of it but when I try to record for the 2nd time, I can't hear the playback and an exception generates:

Exception: javax.sound.sampled.LineUnavailableException - line with format PCM_SIGNED 44100.0 Hz, 8 bit, mono, 1 bytes/frame, not supported.

enter image description here

Does anybody know how to fix this?

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
Compte Gmail
  • 137
  • 3
  • 8

1 Answers1

1

This isn't thrown by Codename One, it's thrown by Java Sound. Based on the answer to this question: javax.sound.sampled.LineUnavailableException : Why am I getting this exception?

It seems that 24 bit only works for Java on Linux/Mac and on the devices. Use 16 to work on Windows too. It seems that this is true also in the other direction and 1 bit frames are probably unsupported on Windows.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thank you very much, Shai for your response! So that surely means I can't use that code since it's not compatible with windows? Or should I edit a specific line? – Compte Gmail May 10 '21 at 09:55
  • You just need to tune the variables. Notice that this is an advanced low level API for Audio processing. You might be served better with an API like `Capture` etc – Shai Almog May 11 '21 at 02:02