File tree Expand file tree Collapse file tree 5 files changed +43
-15
lines changed
apps/speech-to-text/screens
packages/react-native-executorch/src Expand file tree Collapse file tree 5 files changed +43
-15
lines changed Original file line number Diff line number Diff line change @@ -10,17 +10,22 @@ import {
1010 Platform ,
1111} from 'react-native' ;
1212import { SafeAreaProvider , SafeAreaView } from 'react-native-safe-area-context' ;
13- import { useSpeechToText , WHISPER_TINY_EN } from 'react-native-executorch' ;
13+ import {
14+ importLegacyExpoFSModules ,
15+ useSpeechToText ,
16+ WHISPER_TINY_EN ,
17+ } from 'react-native-executorch' ;
1418import FontAwesome from '@expo/vector-icons/FontAwesome' ;
1519import {
1620 AudioManager ,
1721 AudioRecorder ,
1822 AudioContext ,
1923} from 'react-native-audio-api' ;
20- import * as FileSystem from 'expo-file-system/legacy' ;
2124import SWMIcon from '../assets/swm_icon.svg' ;
2225import DeviceInfo from 'react-native-device-info' ;
2326
27+ const { cacheDirectory, downloadAsync } = importLegacyExpoFSModules ( ) ;
28+
2429const isSimulator = DeviceInfo . isEmulatorSync ( ) ;
2530
2631export const SpeechToTextScreen = ( ) => {
@@ -56,9 +61,9 @@ export const SpeechToTextScreen = () => {
5661 return ;
5762 }
5863
59- const { uri } = await FileSystem . downloadAsync (
64+ const { uri } = await downloadAsync (
6065 audioURL ,
61- FileSystem . cacheDirectory + 'audio_file'
66+ cacheDirectory + 'audio_file'
6267 ) ;
6368
6469 const audioContext = new AudioContext ( { sampleRate : 16000 } ) ;
Original file line number Diff line number Diff line change 1- import { documentDirectory } from 'expo-file-system/legacy' ;
1+ import { importLegacyExpoFSModules } from '../utils/ResourceFetcher' ;
2+
3+ const { documentDirectory } = importLegacyExpoFSModules ( ) ;
24
35export const RNEDirectory = `${ documentDirectory } react-native-executorch/` ;
Original file line number Diff line number Diff line change 11import { ResourceSource } from '../types/common' ;
2- import { ResourceFetcher } from '../utils/ResourceFetcher' ;
2+ import {
3+ importLegacyExpoFSModules ,
4+ ResourceFetcher ,
5+ } from '../utils/ResourceFetcher' ;
36import { ETError , getError } from '../Error' ;
47import { Template } from '@huggingface/jinja' ;
58import { DEFAULT_CHAT_CONFIG } from '../constants/llmDefaults' ;
@@ -13,7 +16,7 @@ import {
1316} from '../types/llm' ;
1417import { parseToolCall } from '../utils/llm' ;
1518import { Logger } from '../common/Logger' ;
16- import { readAsStringAsync } from 'expo-file-system/legacy' ;
19+ const { readAsStringAsync } = importLegacyExpoFSModules ( ) ;
1720
1821export class LLMController {
1922 private nativeModule : any ;
Original file line number Diff line number Diff line change 2727 * - Implements linked list behavior via the `.next` attribute
2828 * - Automatically processes subsequent downloads when `.next` contains a valid resource
2929 */
30+ import type * as FileSystemTypes from 'expo-file-system' ;
3031
31- import {
32+ export function importLegacyExpoFSModules ( ) {
33+ let FileSystem : typeof FileSystemTypes ;
34+
35+ try {
36+ const expoPkg = require ( 'expo/package.json' ) ;
37+ const sdkVersion = expoPkg . version . split ( '.' ) [ 0 ] ;
38+
39+ if ( Number ( sdkVersion ) > 53 ) {
40+ FileSystem = require ( 'expo-file-system/legacy' ) ;
41+ } else {
42+ FileSystem = require ( 'expo-file-system' ) ;
43+ }
44+ } catch ( e ) {
45+ throw new Error ( 'Expo must be installed to use react-native-executorch' ) ;
46+ }
47+ return FileSystem ;
48+ }
49+
50+ const {
3251 cacheDirectory,
3352 copyAsync,
3453 createDownloadResumable,
@@ -38,7 +57,8 @@ import {
3857 EncodingType,
3958 deleteAsync,
4059 readDirectoryAsync,
41- } from 'expo-file-system/legacy' ;
60+ } = importLegacyExpoFSModules ( ) ;
61+
4262import { Asset } from 'expo-asset' ;
4363import { Platform } from 'react-native' ;
4464import { RNEDirectory } from '../constants/directories' ;
Original file line number Diff line number Diff line change 1+ import type * as FileSystemTypes from 'expo-file-system' ;
12import { RNEDirectory } from '../constants/directories' ;
23import { ResourceSource } from '../types/common' ;
34import { Asset } from 'expo-asset' ;
45import { Logger } from '../common/Logger' ;
6+ import { importLegacyExpoFSModules } from './ResourceFetcher' ;
57
68/**
79 * @internal
810 */
9- import {
10- getInfoAsync ,
11- makeDirectoryAsync ,
12- type DownloadResumable ,
13- } from 'expo-file-system/legacy' ;
11+ const { getInfoAsync, makeDirectoryAsync } = importLegacyExpoFSModules ( ) ;
1412
1513export const enum HTTP_CODE {
1614 OK = 200 ,
@@ -42,7 +40,7 @@ export interface ResourceSourceExtended {
4240}
4341
4442export interface DownloadResource {
45- downloadResumable : DownloadResumable ;
43+ downloadResumable : FileSystemTypes . DownloadResumable ;
4644 status : DownloadStatus ;
4745 extendedInfo : ResourceSourceExtended ;
4846}
You can’t perform that action at this time.
0 commit comments