# AudioSource


```
class AudioSource
```

<br />

*** ** * ** ***

The input source (e.g. microphone, file) for audio.

## Summary

| ### Public functions |
|---|---|
| `java-static https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi.html(value = https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#S) https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource#fromMic()()` Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` from the microphone. |
| `java-static https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource#fromPfd(android.os.ParcelFileDescriptor)(pfd: https://developer.android.com/reference/android/os/ParcelFileDescriptor.html)` Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` from a `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html`. |

## Public functions

### fromMic

```
@RequiresApi(value = Build.VERSION_CODES.S)
java-static fun fromMic(): AudioSource
```

Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` from the microphone.

**Note:** This API requires the `android.permission.RECORD_AUDIO` permission. Make sure to declare it in your AndroidManifest.xml:

```kotlin
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```

### fromPfd

```
java-static fun fromPfd(pfd: ParcelFileDescriptor): AudioSource
```

Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/audio/AudioSource` from a `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html`.

The input must be raw, headerless audio data in a mono (single channel), 16-bit PCM format with a 16 kHz sample rate.

Furthermore, the file descriptor must supply data at a real-time pace (e.g., producing approximately 16K of new data every second). Direct file-based file descriptors are not supported at this moment as they do not provide data at real-time speed.