Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

57
LINES

< > BotCompany Repo | #1027054 // Android Send Audio To Raspi v1 [works, but doesn't seem to use Bluetooth headset]

JavaX source code (Android) [tags: use-pretranspiled] - run with: the app

Libraryless. Click here for Pure Java version (5280L/35K/120K).

1  
!7
2  
3  
set flag Android. set flag AndroidOnly. set flag NoAWT.
4  
5  
import android.media.*;
6  
7  
static int bufferSize = 8192;
8  
9  
// raspi home, X20
10  
static LS ips = ll("192.168.2.165", "192.168.43.244");
11  
12  
static AudioRecord recorder;
13  
static new L<StefansOS_ConnectToServer> senders;
14  
15  
p {
16  
  for (S ip : ips) {
17  
    print("Connecting to " + ip);
18  
    new StefansOS_ConnectToServer sender;
19  
    sender.server = ip;
20  
    sender.start();
21  
    senders.add(sender);
22  
  }
23  
  
24  
  print("Making recorder");
25  
  
26  
  recorder = new AudioRecord.Builder()
27  
    .setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION)
28  
    .setAudioFormat(new AudioFormat.Builder()
29  
      .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
30  
      .setSampleRate(16000)
31  
      .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
32  
      .build())
33  
   .setBufferSizeInBytes(bufferSize)
34  
   .build();
35  
  print("Made recorder");
36  
  
37  
  recorder.startRecording();
38  
  print("Started recording");
39  
  
40  
  byte[] buf = new[bufferSize];
41  
  
42  
  while licensed {
43  
    printWithTime("Read bytes: " + recorder.read(buf, 0, l(buf), AudioRecord.READ_BLOCKING);
44  
    S line = "audio: " + base64(buf);
45  
    for (StefansOS_ConnectToServer sender : senders) pcall {
46  
      sender.sendLine(line);
47  
    }
48  
  }
49  
  
50  
  /*recorder.release();
51  
  print("Released recorder");*/
52  
}
53  
54  
svoid cleanMeUp {
55  
  if (recorder != null) recorder.release();
56  
  dispose senders;
57  
}

Author comment

Began life as a copy of #1027051

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027054
Snippet name: Android Send Audio To Raspi v1 [works, but doesn't seem to use Bluetooth headset]
Eternal ID of this version: #1027054/1
Text MD5: 11f8aba7ac51a446c109919c722d23fb
Transpilation MD5: d522c111328a4adeea16b14ec092565b
Author: stefan
Category: javax / android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-15 14:23:39
Source code size: 1403 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 284 / 339
Referenced in: [show references]