Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Đầu vào micrô
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi ghi âm thanh, Audio HAL sẽ nhận được lệnh gọi openInputStream
có chứa đối số AudioSource
để cho biết cách xử lý đầu vào micrô.
Nguồn VOICE_RECOGNITION
dự kiến một luồng micrô âm thanh nổi có hiệu ứng loại bỏ tiếng vọng (nếu có) nhưng không có quy trình xử lý nào khác được áp dụng cho luồng đó.
Để ghi âm từ một thiết bị có nhiều hơn hai kênh (âm thanh nổi), hãy sử dụng mặt nạ chỉ mục kênh thay vì mặt nạ chỉ mục vị trí (chẳng hạn như CHANNEL_IN_LEFT
). Ví dụ:
final AudioFormat audioFormat = new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(44100)
.setChannelIndexMask(0xf /* 4 channels, 0..3 */)
.build();
final AudioRecord audioRecord = new AudioRecord.Builder()
.setAudioFormat(audioFormat)
.build();
audioRecord.setPreferredDevice(someAudioDeviceInfo);
Khi bạn đặt cả setChannelMask
và setChannelIndexMask
, AudioRecord
chỉ sử dụng giá trị do setChannelMask
đặt (tối đa là hai kênh).
Chụp đồng thời
Kể từ Android 10, khung Android hỗ trợ tính năng Ghi đồng thời dữ liệu đầu vào, nhưng có các hạn chế để bảo vệ quyền riêng tư của người dùng. Trong số các quy định hạn chế này, các nguồn ảo như AUDIO_SOURCE_FM_TUNER
sẽ bị bỏ qua và được phép ghi lại đồng thời với một đầu vào thông thường (chẳng hạn như micrô).
HwAudioSource
không được xem là một phần của các quy tắc hạn chế chụp đồng thời.
Các ứng dụng được thiết kế để hoạt động với thiết bị AUDIO_DEVICE_IN_BUS
hoặc với thiết bị AUDIO_DEVICE_IN_FM_TUNER
phụ phải dựa vào việc xác định rõ ràng các thiết bị đó và sử dụng AudioRecord.setPreferredDevice()
để bỏ qua logic lựa chọn nguồn mặc định của Android.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-09 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-09 UTC."],[],[],null,["# Microphone input\n\nWhen capturing audio, the Audio HAL receives an `openInputStream` call that\nincludes an `AudioSource` argument to indicate how microphone input should be\nprocessed.\n\nThe `VOICE_RECOGNITION` source expects a stereo microphone stream that has an\necho cancellation effect (if available) but no other processing applied to it.\n\nMulti-channel microphone input\n------------------------------\n\nTo capture audio from a device with more than two channels (stereo), use a\nchannel index mask instead of positional index mask (such as `CHANNEL_IN_LEFT`).\nFor example: \n\n final AudioFormat audioFormat = new AudioFormat.Builder()\n .setEncoding(AudioFormat.ENCODING_PCM_16BIT)\n .setSampleRate(44100)\n .setChannelIndexMask(0xf /* 4 channels, 0..3 */)\n .build();\n final AudioRecord audioRecord = new AudioRecord.Builder()\n .setAudioFormat(audioFormat)\n .build();\n audioRecord.setPreferredDevice(someAudioDeviceInfo);\n\nWhen both `setChannelMask` and `setChannelIndexMask` are set, `AudioRecord` uses\nonly the value set by `setChannelMask` (maximum of two channels).\n\nConcurrent capture\n------------------\n\nAs of Android 10, the Android framework supports\n[Concurrent capture](/docs/core/audio/concurrent) of inputs, but with\nrestrictions to protect the user's privacy. As part of these restrictions,\nvirtual sources such as `AUDIO_SOURCE_FM_TUNER` are ignored, and are allowed to\nbe captured concurrently along with a regular input (such as the microphone).\n`HwAudioSource` is not considered part of the concurrent capture restrictions.\n\nApps designed to work with `AUDIO_DEVICE_IN_BUS` devices or with secondary\n`AUDIO_DEVICE_IN_FM_TUNER` devices must rely on explicitly identifying those\ndevices and using `AudioRecord.setPreferredDevice()` to bypass the Android\ndefault source selection logic."]]