Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Profil audio Bluetooth berdasarkan Audio Bluetooth Hemat Energi (BLE)
memungkinkan streaming dua arah audio berkualitas tinggi (misalnya, audio stereo
dengan frekuensi sampling 32 kHz). Hal ini dimungkinkan berkat dibuatnya LE
Saluran Isokronos (ISO). ISO mirip dengan Synchronous Connection-Oriented
(SCO) karena menggunakan bandwidth nirkabel yang dicadangkan, tetapi
tidak lagi dibatasi hingga 64 Kbps dan dapat disesuaikan secara dinamis.
Input audio Bluetooth dapat menggunakan
AudioManager API untuk hampir semua penggunaan
yang berbeda, kecuali panggilan telepon. Panduan ini membahas cara merekam audio stereo dari
Audio BLE Audio.
Mengonfigurasi aplikasi Anda
Pertama, konfigurasi aplikasi Anda untuk menargetkan SDK yang benar di build.gradle:
targetSdkVersion 31
Daftarkan callback audio
Buat
AudioDeviceCallback
yang memberi tahu aplikasi tentang
perubahan apa pun pada sambungan
AudioDevices.
Dapatkan daftar semua perangkat audio yang terhubung yang mendukung input, lalu gunakan
getType() untuk mengetahui apakah
perangkat adalah {i>headset<i} yang menggunakan
AudioDeviceInfo.TYPE_BLE_HEADSET.
Untuk memeriksa apakah mikrofon stereo didukung pada perangkat yang dipilih, lihat apakah
perangkat memiliki dua saluran
atau lebih. Jika perangkat hanya memiliki satu saluran, setel mask saluran ke mono.
Menyetel perangkat pilihan akan memberi tahu recorder perangkat audio mana
yang ingin Anda rekam.
Kotlin
recorder.preferredDevice=audioDevice
Java
recorder.setPreferredDevice(bleInputDevice);
Sekarang Anda dapat merekam audio seperti yang dijelaskan dalam panduan MediaRecorder.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-18 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[],[],null,["# Audio recording\n\nBluetooth audio profiles based on Bluetooth Low Energy (BLE) Audio\nallow bidirectional streaming of high quality audio (for example, stereo audio\nwith a 32 kHz sampling rate). This is possible thanks to the creation of the LE\nIsochronous Channel (ISO). ISO is similar to the Synchronous Connection-Oriented\n(SCO) Link because it also uses reserved wireless bandwidth, but the bandwidth\nreservation is no longer capped at 64 Kbps and can be dynamically adjusted.\n\nBluetooth audio input can use the latest\n[AudioManager API](/reference/android/media/AudioManager) for nearly all use\ncases, excluding phone calls. This guide covers how to record stereo audio from\nBLE Audio hearables.\n\nConfigure your application\n--------------------------\n\nFirst, configure your application to target the correct SDK in `build.gradle`: \n\n targetSdkVersion 31\n\nRegister audio callback\n-----------------------\n\nCreate an\n[`AudioDeviceCallback`](/reference/android/media/AudioManager#registerAudioDeviceCallback(android.media.AudioDeviceCallback,%20android.os.Handler))\nthat lets your application know of any changes to connected or disconnected\n`AudioDevices`. \n\n final AudioDeviceCallback audioDeviceCallback = new AudioDeviceCallback() {\n @Override\n public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {\n };\n @Override\n public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {\n // Handle device removal\n };\n };\n\n audioManager.registerAudioDeviceCallback(audioDeviceCallback);\n\nFind BLE Audio Device\n---------------------\n\nGet a list of all connected audio devices with input supported, then use\n[`getType()`](/reference/android/media/AudioDeviceInfo#getType()) to see if\nthe device is a headset using\n[`AudioDeviceInfo.TYPE_BLE_HEADSET`](/reference/android/media/AudioDeviceInfo#TYPE_BLE_HEADSET). \n\n### Kotlin\n\n```kotlin\nval allDeviceInfo = audioManager.getDevices(GET_DEVICES_INPUTS)\nvar bleInputDevice: AudioDeviceInfo? = null\n for (device in allDeviceInfo) {\n if (device.type == AudioDeviceInfo.TYPE_BLE_HEADSET) {\n bleInputDevice = device\n break\n }\n }\n```\n\n### Java\n\n```java\nAudioDeviceInfo[] allDeviceInfo = audioManager.getDevices(GET_DEVICES_INPUTS);\nAudioDeviceInfo bleInputDevice = null;\nfor (AudioDeviceInfo device : allDeviceInfo) {\n if (device.getType() == AudioDeviceInfo.TYPE_BLE_HEADSET) {\n bleInputDevice = device;\n break;\n }\n}\n```\n\nStereo support\n--------------\n\nTo check if stereo microphones are supported on the selected device, see if the\ndevice has two or more channels. If the device only has one channel, set the channel mask to mono. \n\n### Kotlin\n\n```kotlin\nvar channelMask: Int = AudioFormat.CHANNEL_IN_MONO\nif (audioDevice.channelCounts.size \u003e= 2) {\n channelMask = AudioFormat.CHANNEL_IN_STEREO\n}\n```\n\n### Java\n\n```java\nif (bleInputDevice.getChannelCounts() \u003e= 2) {\n channelMask = AudioFormat.CHANNEL_IN_STEREO;\n};\n```\n\nSet up the audio recorder\n-------------------------\n\nAudio recorders can be set up using the standard `AudioRecord` builder.\nUse the channel mask to select stereo or mono configuration. \n\n### Kotlin\n\n```kotlin\nval recorder = AudioRecord.Builder()\n .setAudioSource(MediaRecorder.AudioSource.MIC)\n .setAudioFormat(AudioFormat.Builder()\n .setEncoding(AudioFormat.ENCODING_PCM_16BIT)\n .setSampleRate(32000)\n .setChannelMask(channelMask)\n .build())\n .setBufferSizeInBytes(2 * minBuffSizeBytes)\n .build()\n```\n\n### Java\n\n```java\nAudioRecord recorder = new AudioRecord.Builder()\n .setAudioSource(MediaRecorder.AudioSource.MIC)\n .setAudioFormat(new AudioFormat.Builder()\n .setEncoding(AudioFormat.ENCODING_PCM_16BIT)\n .setSampleRate(32000)\n .setChannelMask(channelMask)\n .build())\n .setBufferSizeInBytes(2*minBuffSizeBytes)\n .build();\n```\n\nSet preferred device\n--------------------\n\nSetting a preferred device informs the audio `recorder` which audio device\nyou wish to record with. \n\n### Kotlin\n\n```kotlin\nrecorder.preferredDevice = audioDevice\n```\n\n### Java\n\n```java\nrecorder.setPreferredDevice(bleInputDevice);\n```\n| **Note:** The user can manually override this preference in device settings.\n\nNow, you can record audio as outlined in [the MediaRecorder guide](/guide/topics/media/mediarecorder)."]]