1 | !7 |
2 | |
3 | set flag Android. set flag AndroidOnly. set flag NoAWT. |
4 | |
5 | import android.media.*; |
6 | import android.content.*; |
7 | |
8 | static int bufferSize = 8192; |
9 | |
10 | // raspi home, X20 |
11 | static LS ips = ll("192.168.2.165", "192.168.43.244");
|
12 | |
13 | static AudioRecord recorder; |
14 | static new L<StefansOS_ConnectToServer> senders; |
15 | static new Q qSendAudio; |
16 | static new Q qVoiceOut; |
17 | |
18 | p {
|
19 | for (S ip : ips) {
|
20 | print("Connecting to " + ip);
|
21 | new StefansOS_ConnectToServer sender; |
22 | sender.server = ip; |
23 | sender.onLine = voidfunc(S s) {
|
24 | final new Matches m; |
25 | if (startsWith_trim(s, "voiceOutput:", m)) |
26 | addToQAndPrintSize(+qVoiceOut, r {
|
27 | androidSayInEnglish(m.rest()); |
28 | }); |
29 | }; |
30 | sender.startWithSubs("voiceOutput");
|
31 | senders.add(sender); |
32 | } |
33 | |
34 | BroadcastReceiver brr = new {
|
35 | @Override |
36 | public void onReceive(Context context, Intent intent) {
|
37 | int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,-1); |
38 | print(+state); |
39 | if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {
|
40 | print("Bluetooth Connected");
|
41 | androidContext().unregisterReceiver(this); |
42 | thread { startRecording(); }
|
43 | } |
44 | } |
45 | }; |
46 | |
47 | AudioManager am = cast androidContext().getSystemService(Context.AUDIO_SERVICE); |
48 | androidContext().registerReceiver(brr, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); |
49 | print("Starting Bluetooth");
|
50 | am.setStreamSolo(AudioManager.MODE_IN_CALL, true); |
51 | am.setBluetoothScoOn(true); |
52 | am.setMode(AudioManager.MODE_IN_CALL); |
53 | am.startBluetoothSco(); |
54 | print("Can BT record from mic? " + am.isBluetoothScoAvailableOffCall());
|
55 | } |
56 | |
57 | svoid startRecording {
|
58 | print("Making recorder");
|
59 | |
60 | recorder = new AudioRecord.Builder() |
61 | .setAudioSource( |
62 | //MediaRecorder.AudioSource.VOICE_COMMUNICATION |
63 | MediaRecorder.AudioSource.MIC |
64 | ) |
65 | .setAudioFormat(new AudioFormat.Builder() |
66 | .setEncoding(AudioFormat.ENCODING_PCM_16BIT) |
67 | .setSampleRate(16000) |
68 | .setChannelMask(AudioFormat.CHANNEL_IN_MONO) |
69 | .build()) |
70 | .setBufferSizeInBytes(bufferSize) |
71 | .build(); |
72 | print("Made recorder");
|
73 | |
74 | recorder.startRecording(); |
75 | print("Started recording");
|
76 | |
77 | byte[] buf = new[bufferSize]; |
78 | |
79 | while licensed {
|
80 | //printWithTime("Read bytes: " + recorder.read(buf, 0, l(buf), AudioRecord.READ_BLOCKING);
|
81 | fS line = "audio: " + base64(buf); |
82 | addToQAndPrintSize(+qSendAudio, r {
|
83 | for (StefansOS_ConnectToServer sender : senders) pcall {
|
84 | sender.sendLine(line); |
85 | } |
86 | }); |
87 | } |
88 | |
89 | /*recorder.release(); |
90 | print("Released recorder");*/
|
91 | } |
92 | |
93 | svoid cleanMeUp {
|
94 | if (recorder != null) recorder.release(); |
95 | dispose senders; |
96 | } |
Began life as a copy of #1027055
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: | #1027059 |
| Snippet name: | Find clear print log bug [Android Send Audio Raspi v3] |
| Eternal ID of this version: | #1027059/1 |
| Text MD5: | 82d2133dad092f3f85fb1aa9c6edc628 |
| 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-16 15:55:12 |
| Source code size: | 2743 bytes / 96 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 505 / 516 |
| Referenced in: | [show references] |