> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/XDcobra/react-native-sherpa-onnx/llms.txt
> Use this file to discover all available pages before exploring further.

# Model Path Utilities

> Utilities for resolving and managing model file paths across platforms

This module provides utilities for working with model paths in asset bundles, file systems, and Play Asset Delivery.

## assetModelPath()

Create a model path configuration for models bundled in your app's assets.

```typescript theme={null}
function assetModelPath(assetPath: string): ModelPathConfig
```

### Parameters

<ParamField path="assetPath" type="string" required>
  Path relative to assets directory (e.g., `"models/sherpa-onnx-whisper-tiny"`).
</ParamField>

### Returns

<ResponseField name="ModelPathConfig" type="object">
  Model path configuration with type `'asset'`.
</ResponseField>

### Example

```typescript theme={null}
import { assetModelPath, createSTT } from 'react-native-sherpa-onnx/stt';

const stt = await createSTT({
  modelPath: assetModelPath('models/whisper-tiny-en'),
});
```

***

## fileModelPath()

Create a model path configuration for models in the file system.

```typescript theme={null}
function fileModelPath(filePath: string): ModelPathConfig
```

### Parameters

<ParamField path="filePath" type="string" required>
  Absolute path to model directory. On iOS, use an absolute path from `react-native-fs`:

  ```typescript theme={null}
  DocumentDirectoryPath + '/models/model-name'
  ```
</ParamField>

### Returns

<ResponseField name="ModelPathConfig" type="object">
  Model path configuration with type `'file'`.
</ResponseField>

### Example

```typescript theme={null}
import { fileModelPath, createSTT } from 'react-native-sherpa-onnx/stt';
import { DocumentDirectoryPath } from '@dr.pogodin/react-native-fs';

const modelPath = fileModelPath(
  `${DocumentDirectoryPath}/models/sherpa-onnx-whisper-tiny`
);

const stt = await createSTT({ modelPath });
```

***

## autoModelPath()

Create a model path configuration with automatic path type detection.

```typescript theme={null}
function autoModelPath(path: string): ModelPathConfig
```

Tries asset path first, then falls back to file system path.

### Parameters

<ParamField path="path" type="string" required>
  Path to check (will be tried as both asset and file path).
</ParamField>

### Returns

<ResponseField name="ModelPathConfig" type="object">
  Model path configuration with type `'auto'`.
</ResponseField>

### Example

```typescript theme={null}
import { autoModelPath, createSTT } from 'react-native-sherpa-onnx/stt';

const stt = await createSTT({
  modelPath: autoModelPath('models/whisper-tiny'),
});
```

***

## resolveModelPath()

Resolve a model path configuration to a platform-specific absolute path.

```typescript theme={null}
function resolveModelPath(config: ModelPathConfig): Promise<string>
```

This handles different path types (asset, file, auto) and returns an absolute path that can be used by native code.

### Parameters

<ParamField path="config" type="ModelPathConfig" required>
  Model path configuration from `assetModelPath()`, `fileModelPath()`, or `autoModelPath()`.
</ParamField>

### Returns

<ResponseField name="Promise<string>" type="string">
  Absolute path usable by native code.
</ResponseField>

### Example

```typescript theme={null}
import { resolveModelPath, assetModelPath } from 'react-native-sherpa-onnx';

const config = assetModelPath('models/whisper-tiny');
const absolutePath = await resolveModelPath(config);
console.log(absolutePath);
// iOS: "/path/to/app.app/models/whisper-tiny"
// Android: "models/whisper-tiny" (asset path)
```

***

## listAssetModels()

List all model folders in the assets/models directory.

```typescript theme={null}
function listAssetModels(): Promise<Array<{
  folder: string;
  hint: 'stt' | 'tts' | 'unknown';
}>>
```

Scans the platform-specific model directory and returns folder names with type hints.

### Returns

<ResponseField name="Promise<Array<ModelInfo>>" type="array">
  Array of model information objects.

  <Expandable title="ModelInfo properties">
    <ResponseField name="folder" type="string">
      Model folder name
    </ResponseField>

    <ResponseField name="hint" type="'stt' | 'tts' | 'unknown'">
      Detected model type hint based on folder name patterns
    </ResponseField>
  </Expandable>
</ResponseField>

### Example

```typescript theme={null}
import { listAssetModels } from 'react-native-sherpa-onnx';

const models = await listAssetModels();
console.log('Available models:', models);
// [
//   { folder: 'sherpa-onnx-streaming-zipformer-en-2023-06-26', hint: 'stt' },
//   { folder: 'vits-piper-en_US-lessac-medium', hint: 'tts' }
// ]
```

***

## listModelsAtPath()

List model folders under a specific filesystem path.

```typescript theme={null}
function listModelsAtPath(
  path: string,
  recursive?: boolean
): Promise<Array<{
  folder: string;
  hint: 'stt' | 'tts' | 'unknown';
}>>
```

### Parameters

<ParamField path="path" type="string" required>
  Absolute filesystem path to scan for models.
</ParamField>

<ParamField path="recursive" type="boolean" default={false}>
  When true, returns relative folder paths under the base path recursively.
</ParamField>

### Returns

<ResponseField name="Promise<Array<ModelInfo>>" type="array">
  Array of model information objects (see [listAssetModels()](#listassetmodels)).
</ResponseField>

### Example

```typescript theme={null}
import { listModelsAtPath } from 'react-native-sherpa-onnx';
import { DocumentDirectoryPath } from '@dr.pogodin/react-native-fs';

const modelsPath = `${DocumentDirectoryPath}/sherpa-onnx/models`;
const models = await listModelsAtPath(modelsPath, true);

for (const model of models) {
  console.log(`Found: ${model.folder} (${model.hint})`);
}
```

***

## getAssetPackPath()

**Android Only:** Get the path to models directory inside an Android asset pack delivered via Play Asset Delivery (PAD).

```typescript theme={null}
function getAssetPackPath(packName: string): Promise<string | null>
```

### Parameters

<ParamField path="packName" type="string" required>
  Name of the asset pack (e.g., `"sherpa_models"`).
</ParamField>

### Returns

<ResponseField name="Promise<string | null>" type="string | null">
  Path to the models directory in the asset pack, or `null` if the pack is not available.
</ResponseField>

### Platform Support

* **Android**: Full support with Play Asset Delivery
* **iOS**: Always returns `null`

### Example

```typescript theme={null}
import { getAssetPackPath, listModelsAtPath } from 'react-native-sherpa-onnx';

const packPath = await getAssetPackPath('sherpa_models');
if (packPath) {
  console.log('Asset pack path:', packPath);
  const models = await listModelsAtPath(packPath);
  console.log('Models in pack:', models);
}
```

***

## getDefaultModelPath()

Get the default model directory path for the current platform.

```typescript theme={null}
function getDefaultModelPath(): string
```

Returns a logical name (not an absolute path). On iOS, use absolute paths with `react-native-fs` instead.

### Returns

<ResponseField name="string" type="string">
  * **iOS**: `"Documents/models"`
  * **Android**: `"models"`
</ResponseField>

### Example

```typescript theme={null}
import { getDefaultModelPath } from 'react-native-sherpa-onnx';

const defaultPath = getDefaultModelPath();
console.log(defaultPath);
// iOS: "Documents/models"
// Android: "models"
```

***

## Types

### ModelPathConfig

Model path configuration discriminated union.

```typescript theme={null}
type ModelPathConfig =
  | { type: 'asset'; path: string }
  | { type: 'file'; path: string }
  | { type: 'auto'; path: string };
```

<ParamField path="type" type="'asset' | 'file' | 'auto'" required>
  * `'asset'`: Model is bundled in app assets
  * `'file'`: Model is in file system (absolute path)
  * `'auto'`: Automatically detect (tries asset first, then file)
</ParamField>

<ParamField path="path" type="string" required>
  Path to the model directory.
</ParamField>

***

## See Also

* [STT Initialization](/api/stt/create-stt) - Using model paths with STT
* [TTS Initialization](/api/tts/create-tts) - Using model paths with TTS
* [Model Download Manager](/api/download) - Downloading models at runtime
