public class

AutomotiveCarAudioRecord

extends CarAudioRecord

 java.lang.Object

androidx.car.app.media.CarAudioRecord

↳androidx.car.app.media.AutomotiveCarAudioRecord

Gradle dependencies

compile group: 'androidx.car.app', name: 'app-automotive', version: '1.7.0-beta01'

  • groupId: androidx.car.app
  • artifactId: app-automotive
  • version: 1.7.0-beta01

Artifact androidx.car.app:app-automotive:1.7.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

A CarAudioRecord for automotive OS.

Summary

Fields
from CarAudioRecordAUDIO_CONTENT_BUFFER_SIZE, AUDIO_CONTENT_MIME, AUDIO_CONTENT_SAMPLING_RATE
Constructors
publicAutomotiveCarAudioRecord(CarContext carContext)

Methods
protected abstract intreadInternal(byte[] audioData[], int offsetInBytes, int sizeInBytes)

Performs internal platform specific read behavior.

protected abstract voidstartRecordingInternal(OpenMicrophoneResponse openMicrophoneResponse)

Performs internal platform specific start recording behavior.

protected abstract voidstopRecordingInternal()

Performs internal platform specific stop recording behavior.

from CarAudioRecordcreate, read, startRecording, stopRecording
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public AutomotiveCarAudioRecord(CarContext carContext)

Methods

protected abstract void startRecordingInternal(OpenMicrophoneResponse openMicrophoneResponse)

Performs internal platform specific start recording behavior.

Parameters:

openMicrophoneResponse: the response from the host for opening the microphone

protected abstract void stopRecordingInternal()

Performs internal platform specific stop recording behavior.

protected abstract int readInternal(byte[] audioData[], int offsetInBytes, int sizeInBytes)

Performs internal platform specific read behavior.

Parameters:

audioData: the array to which the recorded audio data is written
offsetInBytes: index in audioData from which the data is written expressed in bytes
sizeInBytes: the number of requested bytes

Returns:

the number of bytes that were read, or -1 if there isn't any more microphone data to read. The number of bytes will be a multiple of the frame size in bytes not to exceed sizeInBytes

Source

/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.car.app.media;

import static android.Manifest.permission.RECORD_AUDIO;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresPermission;
import androidx.annotation.RestrictTo;
import androidx.car.app.CarContext;
import androidx.car.app.annotations.CarProtocol;
import androidx.car.app.annotations.KeepFields;

/**
 * A {@link CarAudioRecord} for automotive OS.
 *
 */
@RestrictTo(LIBRARY_GROUP)
@KeepFields
@CarProtocol
public class AutomotiveCarAudioRecord extends CarAudioRecord {
    /**
     * Only used for Automotive, as the car microphone is the device microphone.
     */
    @NonNull
    private final AudioRecord mAudioRecord;

    @RequiresPermission(RECORD_AUDIO)
    public AutomotiveCarAudioRecord(
            @NonNull CarContext carContext) {
        super(carContext);
        mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, AUDIO_CONTENT_SAMPLING_RATE,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_DEFAULT, AUDIO_CONTENT_BUFFER_SIZE);
    }

    @Override
    protected void startRecordingInternal(
            @NonNull OpenMicrophoneResponse openMicrophoneResponse) {
        mAudioRecord.startRecording();
    }

    @Override
    protected void stopRecordingInternal() {
        mAudioRecord.stop();
    }

    @Override
    protected int readInternal(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes) {
        return mAudioRecord.read(audioData, offsetInBytes, sizeInBytes);
    }
}