Merge "Add HOTWORD as an AudioSource" into klp-dev
This commit is contained in:
@@ -190,7 +190,7 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
|
||||
int frameSize = nbChannels * bytesPerSample;
|
||||
size_t frameCount = buffSizeInBytes / frameSize;
|
||||
|
||||
if (uint32_t(source) >= AUDIO_SOURCE_CNT) {
|
||||
if ((uint32_t(source) >= AUDIO_SOURCE_CNT) && (uint32_t(source) != AUDIO_SOURCE_HOTWORD)) {
|
||||
ALOGE("Error creating AudioRecord: unknown source.");
|
||||
return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
|
||||
}
|
||||
@@ -387,6 +387,9 @@ static jint android_media_AudioRecord_readInByteArray(JNIEnv *env, jobject thiz
|
||||
(jint)recorderBuffSize : sizeInBytes );
|
||||
env->ReleaseByteArrayElements(javaAudioData, recordBuff, 0);
|
||||
|
||||
if (readSize < 0) {
|
||||
readSize = AUDIORECORD_ERROR_INVALID_OPERATION;
|
||||
}
|
||||
return (jint) readSize;
|
||||
}
|
||||
|
||||
@@ -427,8 +430,12 @@ static jint android_media_AudioRecord_readInDirectBuffer(JNIEnv *env, jobject t
|
||||
}
|
||||
|
||||
// read new data from the recorder
|
||||
return (jint) lpRecorder->read(nativeFromJavaBuf,
|
||||
ssize_t readSize = lpRecorder->read(nativeFromJavaBuf,
|
||||
capacity < sizeInBytes ? capacity : sizeInBytes);
|
||||
if (readSize < 0) {
|
||||
readSize = AUDIORECORD_ERROR_INVALID_OPERATION;
|
||||
}
|
||||
return (jint)readSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2084,6 +2084,14 @@
|
||||
android:description="@string/permdesc_captureAudioOutput"
|
||||
android:protectionLevel="signature|system" />
|
||||
|
||||
<!-- Allows an application to capture audio for hotword detection.
|
||||
<p>Not for use by third-party applications.</p>
|
||||
@hide -->
|
||||
<permission android:name="android.permission.CAPTURE_AUDIO_HOTWORD"
|
||||
android:label="@string/permlab_captureAudioHotword"
|
||||
android:description="@string/permdesc_captureAudioHotword"
|
||||
android:protectionLevel="signature|system" />
|
||||
|
||||
<!-- Allows an application to capture video output.
|
||||
<p>Not for use by third-party applications.</p> -->
|
||||
<permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
|
||||
|
||||
@@ -1404,6 +1404,12 @@
|
||||
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||
<string name="permdesc_captureAudioOutput">Allows the app to capture and redirect audio output.</string>
|
||||
|
||||
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||
<string name="permlab_captureAudioHotword">Hotword detection</string>
|
||||
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||
<string name="permdesc_captureAudioHotword">Allows the app to capture audio for Hotword detection. The capture can
|
||||
happen in the background but does not prevent other audio capture (e.g. Camcorder).</string>
|
||||
|
||||
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||
<string name="permlab_captureVideoOutput">capture video output</string>
|
||||
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||
|
||||
@@ -1530,16 +1530,6 @@ public class AudioManager {
|
||||
return AudioSystem.isStreamActiveRemotely(STREAM_MUSIC, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* Checks whether speech recognition is active
|
||||
* @return true if a recording with source {@link MediaRecorder.AudioSource#VOICE_RECOGNITION}
|
||||
* is underway.
|
||||
*/
|
||||
public boolean isSpeechRecognitionActive() {
|
||||
return AudioSystem.isSourceActive(MediaRecorder.AudioSource.VOICE_RECOGNITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* Checks whether the current audio focus is exclusive.
|
||||
|
||||
@@ -252,7 +252,8 @@ public class AudioRecord
|
||||
//--------------
|
||||
// audio source
|
||||
if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
|
||||
(audioSource > MediaRecorder.getAudioSourceMax()) ) {
|
||||
((audioSource > MediaRecorder.getAudioSourceMax()) &&
|
||||
(audioSource != MediaRecorder.AudioSource.HOTWORD)) ) {
|
||||
throw new IllegalArgumentException("Invalid audio source.");
|
||||
}
|
||||
mRecordSource = audioSource;
|
||||
|
||||
@@ -200,6 +200,19 @@ public class MediaRecorder
|
||||
* </p>
|
||||
*/
|
||||
public static final int REMOTE_SUBMIX = 8;
|
||||
|
||||
/**
|
||||
* Audio source for preemptible, low-priority software hotword detection
|
||||
* It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}.
|
||||
* <p>
|
||||
* An application should use this audio source when it wishes to do
|
||||
* always-on software hotword detection, while gracefully giving in to any other application
|
||||
* that might want to read from the microphone.
|
||||
* </p>
|
||||
* This is a hidden audio source.
|
||||
* @hide
|
||||
*/
|
||||
protected static final int HOTWORD = 1999;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user