!7 set flag Android. set flag AndroidOnly. set flag NoAWT. import android.media.*; import android.content.*; static int bufferSize = 8192; // raspi home, X20 static LS ips = ll("192.168.2.165", "192.168.43.244"); static AudioRecord recorder; static new L senders; static new Q qSendAudio; static new Q qVoiceOut; p { for (S ip : ips) { print("Connecting to " + ip); new StefansOS_ConnectToServer sender; sender.server = ip; sender.onLine = voidfunc(S s) { final new Matches m; if (startsWith_trim(s, "voiceOutput:", m)) addToQAndPrintSize(+qVoiceOut, r { androidSayInEnglish(m.rest()); }); }; sender.startWithSubs("voiceOutput"); senders.add(sender); } BroadcastReceiver brr = new { @Override public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,-1); print(+state); if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) { print("Bluetooth Connected"); androidContext().unregisterReceiver(this); thread { startRecording(); } } } }; AudioManager am = cast androidContext().getSystemService(Context.AUDIO_SERVICE); androidContext().registerReceiver(brr, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); print("Starting Bluetooth"); am.setStreamSolo(AudioManager.MODE_IN_CALL, true); am.setBluetoothScoOn(true); am.setMode(AudioManager.MODE_IN_CALL); am.startBluetoothSco(); print("Can BT record from mic? " + am.isBluetoothScoAvailableOffCall()); } svoid startRecording { print("Making recorder"); recorder = new AudioRecord.Builder() .setAudioSource( //MediaRecorder.AudioSource.VOICE_COMMUNICATION MediaRecorder.AudioSource.MIC ) .setAudioFormat(new AudioFormat.Builder() .setEncoding(AudioFormat.ENCODING_PCM_16BIT) .setSampleRate(16000) .setChannelMask(AudioFormat.CHANNEL_IN_MONO) .build()) .setBufferSizeInBytes(bufferSize) .build(); print("Made recorder"); recorder.startRecording(); print("Started recording"); byte[] buf = new[bufferSize]; while licensed { //printWithTime("Read bytes: " + recorder.read(buf, 0, l(buf), AudioRecord.READ_BLOCKING); fS line = "audio: " + base64(buf); addToQAndPrintSize(+qSendAudio, r { for (StefansOS_ConnectToServer sender : senders) pcall { sender.sendLine(line); } }); } /*recorder.release(); print("Released recorder");*/ } svoid cleanMeUp { if (recorder != null) recorder.release(); dispose senders; }