add readme. fix downloader operation.

This commit is contained in:
Jordan Hewitt
2025-02-28 14:38:36 -08:00
parent 4549442bd8
commit d00e6d62ff
4 changed files with 145 additions and 201 deletions

View File

@ -3,7 +3,7 @@ import * as FileSystem from "expo-file-system";
import { File, Paths } from 'expo-file-system/next';
import { getDb } from "./db";
export const WHISPER_MODEL_PATH = Paths.join(FileSystem.bundleDirectory || "file:///", "whisper");
export const WHISPER_MODEL_PATH = Paths.join(FileSystem.documentDirectory || "file:///", "whisper");
export const WHISPER_MODEL_DIR = new File(WHISPER_MODEL_PATH);
// Thanks to https://medium.com/@fabi.mofar/downloading-and-saving-files-in-react-native-expo-5b3499adda84
@ -51,19 +51,19 @@ export type whisper_model_tag_t = (typeof WHISPER_MODEL_TAGS)[number];
export const WHISPER_MODELS = {
small: {
source:
"https://huggingface.co/openai/whisper-small/blob/main/pytorch_model.bin",
"https://huggingface.co/openai/whisper-small/blob/resolve/pytorch_model.bin",
target: "small.bin",
label: "Small",
},
medium: {
source:
"https://huggingface.co/openai/whisper-medium/blob/main/pytorch_model.bin",
"https://huggingface.co/openai/whisper-medium/resolve/main/pytorch_model.bin",
target: "medium.bin",
label: "Medium",
},
large: {
source:
"https://huggingface.co/openai/whisper-large/blob/main/pytorch_model.bin",
"https://huggingface.co/openai/whisper-large/resolve/main/pytorch_model.bin",
target: "large.bin",
label: "Large",
},
@ -167,12 +167,9 @@ export async function initiateWhisperDownload(
console.debug("Starting download of %s", whisper_model);
if (!WHISPER_MODEL_DIR.exists) {
await FileSystem.makeDirectoryAsync(WHISPER_MODEL_PATH, {
intermediates: true,
});
console.debug("Created %s", WHISPER_MODEL_DIR);
}
const whisperTarget = getWhisperTarget(whisper_model);
@ -197,7 +194,14 @@ export async function initiateWhisperDownload(
const resumable = FileSystem.createDownloadResumable(
spec.source,
whisperTarget.uri,
{},
{
md5: true,
headers: {
'Content-Type': 'application/octet-stream',
'Accept': 'application/octet-stream',
},
sessionType: FileSystem.FileSystemSessionType.BACKGROUND
},
// On each data write, update the whisper model download status.
// Note that since createDownloadResumable callback only works in the foreground,
// a background process will also be updating the file size.