Skip to content

Commit d127ee8

Browse files
committed
refactor: remove TurboModule/JSI legacy code
- Remove isNewArchitecture() and hasZeroCopySupport() functions - Remove JSI detection and zero-copy code paths - Simplify all managers to use native bridge directly - Clean up test file imports
1 parent f9648ef commit d127ee8

5 files changed

Lines changed: 38 additions & 130 deletions

File tree

__tests__/FluidAudio.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('FluidAudio', () => {
196196
const segments = vad.getSpeechSegments(mockResult);
197197

198198
expect(segments.length).toBe(1);
199-
expect(segments[0].start).toBe(0);
199+
expect(segments[0]!.start).toBe(0);
200200
});
201201
});
202202

__tests__/types.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import type {
22
SystemInfo,
33
ASRConfig,
44
ASRResult,
5-
ASRInitResult,
65
StreamingASRConfig,
76
StreamingUpdate,
87
VADConfig,
98
VADResult,
109
VADChunkResult,
1110
DiarizationConfig,
12-
DiarizationResult,
1311
SpeakerSegment,
1412
KnownSpeaker,
1513
TTSConfig,

src/FluidAudio.ts

Lines changed: 37 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,18 @@ const LINKING_ERROR =
2525
'- You rebuilt the app after installing the package\n' +
2626
'- You are not using Expo Go (Expo does not support native modules)\n';
2727

28-
// Try TurboModule first (New Architecture), fallback to legacy bridge
29-
const FluidAudioNative: FluidAudioNativeModule = (() => {
30-
// Check for TurboModule (New Architecture)
31-
if ((global as any).__turboModuleProxy) {
32-
try {
33-
const turboModule = require('./NativeFluidAudio').default;
34-
if (turboModule) return turboModule;
35-
} catch {}
36-
}
37-
38-
// Fallback to legacy bridge
39-
return NativeModules.FluidAudioModule
40-
? NativeModules.FluidAudioModule
41-
: new Proxy(
42-
{},
43-
{
44-
get() {
45-
throw new Error(LINKING_ERROR);
46-
},
47-
}
48-
);
49-
})();
50-
51-
const eventEmitter = new NativeEventEmitter(
52-
NativeModules.FluidAudioModule ?? FluidAudioNative
53-
);
54-
55-
/**
56-
* Check if JSI bindings are available (New Architecture with zero-copy)
57-
*/
58-
function hasJSI(): boolean {
59-
return (
60-
typeof global !== 'undefined' &&
61-
typeof (global as any).FluidAudio_transcribeAudioBuffer === 'function'
62-
);
63-
}
64-
65-
/**
66-
* Check if using New Architecture (TurboModules)
67-
*/
68-
export function isNewArchitecture(): boolean {
69-
return !!(global as any).__turboModuleProxy;
70-
}
28+
const FluidAudioNative: FluidAudioNativeModule = NativeModules.FluidAudioModule
29+
? NativeModules.FluidAudioModule
30+
: new Proxy(
31+
{},
32+
{
33+
get() {
34+
throw new Error(LINKING_ERROR);
35+
},
36+
}
37+
);
7138

72-
/**
73-
* Check if zero-copy JSI is available
74-
*/
75-
export function hasZeroCopySupport(): boolean {
76-
return hasJSI();
77-
}
39+
const eventEmitter = new NativeEventEmitter(NativeModules.FluidAudioModule);
7840

7941
// ============================================================================
8042
// Event Subscription Helpers
@@ -137,8 +99,6 @@ export async function isAppleSilicon(): Promise<boolean> {
13799

138100
/**
139101
* ASR Manager for speech-to-text transcription
140-
*
141-
* Supports both legacy bridge (base64) and JSI (zero-copy ArrayBuffer)
142102
*/
143103
export class ASRManager {
144104
private initialized = false;
@@ -163,26 +123,18 @@ export class ASRManager {
163123
}
164124

165125
/**
166-
* Transcribe audio from ArrayBuffer (zero-copy with JSI when available)
126+
* Transcribe audio from ArrayBuffer
167127
* @param audioBuffer ArrayBuffer containing 16-bit PCM audio
168128
* @param sampleRate Sample rate of the audio (will be resampled to 16kHz)
169129
*/
170130
async transcribeBuffer(audioBuffer: ArrayBuffer, sampleRate: number = 16000): Promise<ASRResult> {
171131
this.ensureInitialized();
172-
173-
if (hasJSI()) {
174-
// Zero-copy path via JSI
175-
return (global as any).FluidAudio_transcribeAudioBuffer(audioBuffer, sampleRate);
176-
} else {
177-
// Legacy path: convert to base64
178-
const base64 = arrayBufferToBase64(audioBuffer);
179-
return FluidAudioNative.transcribeAudioData(base64, sampleRate);
180-
}
132+
const base64 = arrayBufferToBase64(audioBuffer);
133+
return FluidAudioNative.transcribeAudioData(base64, sampleRate);
181134
}
182135

183136
/**
184-
* Transcribe raw audio data (legacy base64 API)
185-
* @deprecated Use transcribeBuffer() for better performance
137+
* Transcribe raw audio data
186138
* @param base64Audio Base64-encoded 16-bit PCM audio
187139
* @param sampleRate Sample rate of the audio (will be resampled to 16kHz)
188140
*/
@@ -211,8 +163,6 @@ export class ASRManager {
211163

212164
/**
213165
* Streaming ASR Manager for real-time transcription
214-
*
215-
* Supports both legacy bridge (base64) and JSI (zero-copy ArrayBuffer)
216166
*/
217167
export class StreamingASRManager {
218168
private streaming = false;
@@ -237,27 +187,19 @@ export class StreamingASRManager {
237187
}
238188

239189
/**
240-
* Feed audio data using ArrayBuffer (zero-copy with JSI when available)
190+
* Feed audio data using ArrayBuffer
241191
* @param audioBuffer ArrayBuffer containing 16-bit PCM audio at 16kHz
242192
*/
243193
async feedBuffer(audioBuffer: ArrayBuffer): Promise<void> {
244194
if (!this.streaming) {
245195
throw new Error('Streaming not started. Call start() first.');
246196
}
247-
248-
if (hasJSI()) {
249-
// Zero-copy synchronous path via JSI
250-
(global as any).FluidAudio_feedStreamingAudioBuffer(audioBuffer);
251-
} else {
252-
// Legacy path: convert to base64
253-
const base64 = arrayBufferToBase64(audioBuffer);
254-
await FluidAudioNative.feedStreamingAudio(base64);
255-
}
197+
const base64 = arrayBufferToBase64(audioBuffer);
198+
await FluidAudioNative.feedStreamingAudio(base64);
256199
}
257200

258201
/**
259-
* Feed audio data (legacy base64 API)
260-
* @deprecated Use feedBuffer() for better performance
202+
* Feed audio data
261203
* @param base64Audio Base64-encoded 16-bit PCM audio at 16kHz
262204
*/
263205
async feedAudio(base64Audio: string): Promise<void> {
@@ -293,8 +235,6 @@ export class StreamingASRManager {
293235

294236
/**
295237
* VAD Manager for voice activity detection
296-
*
297-
* Supports both legacy bridge (base64) and JSI (zero-copy ArrayBuffer)
298238
*/
299239
export class VADManager {
300240
private initialized = false;
@@ -317,23 +257,17 @@ export class VADManager {
317257
}
318258

319259
/**
320-
* Process audio buffer for voice activity (zero-copy with JSI when available)
260+
* Process audio buffer for voice activity
321261
* @param audioBuffer ArrayBuffer containing 16-bit PCM audio at 16kHz
322262
*/
323263
async processBuffer(audioBuffer: ArrayBuffer): Promise<VADResult> {
324264
this.ensureInitialized();
325-
326-
if (hasJSI()) {
327-
return (global as any).FluidAudio_processVadBuffer(audioBuffer);
328-
} else {
329-
const base64 = arrayBufferToBase64(audioBuffer);
330-
return FluidAudioNative.processVadAudioData(base64);
331-
}
265+
const base64 = arrayBufferToBase64(audioBuffer);
266+
return FluidAudioNative.processVadAudioData(base64);
332267
}
333268

334269
/**
335-
* Process raw audio data for voice activity (legacy base64 API)
336-
* @deprecated Use processBuffer() for better performance
270+
* Process raw audio data for voice activity
337271
* @param base64Audio Base64-encoded 16-bit PCM audio at 16kHz
338272
*/
339273
async process(base64Audio: string): Promise<VADResult> {
@@ -397,8 +331,6 @@ export class VADManager {
397331

398332
/**
399333
* Diarization Manager for speaker identification
400-
*
401-
* Supports both legacy bridge (base64) and JSI (zero-copy ArrayBuffer)
402334
*/
403335
export class DiarizationManager {
404336
private initialized = false;
@@ -423,24 +355,18 @@ export class DiarizationManager {
423355
}
424356

425357
/**
426-
* Diarize audio buffer (zero-copy with JSI when available)
358+
* Diarize audio buffer
427359
* @param audioBuffer ArrayBuffer containing 16-bit PCM audio
428360
* @param sampleRate Sample rate of the audio (will be resampled to 16kHz)
429361
*/
430362
async diarizeBuffer(audioBuffer: ArrayBuffer, sampleRate: number = 16000): Promise<DiarizationResult> {
431363
this.ensureInitialized();
432-
433-
if (hasJSI()) {
434-
return (global as any).FluidAudio_performDiarizationBuffer(audioBuffer, sampleRate);
435-
} else {
436-
const base64 = arrayBufferToBase64(audioBuffer);
437-
return FluidAudioNative.performDiarizationOnAudioData(base64, sampleRate);
438-
}
364+
const base64 = arrayBufferToBase64(audioBuffer);
365+
return FluidAudioNative.performDiarizationOnAudioData(base64, sampleRate);
439366
}
440367

441368
/**
442-
* Perform speaker diarization on raw audio data (legacy base64 API)
443-
* @deprecated Use diarizeBuffer() for better performance
369+
* Perform speaker diarization on raw audio data
444370
* @param base64Audio Base64-encoded 16-bit PCM audio
445371
* @param sampleRate Sample rate of the audio (will be resampled to 16kHz)
446372
*/
@@ -500,7 +426,7 @@ export class DiarizationManager {
500426
// ============================================================================
501427

502428
/**
503-
* TTS Result with ArrayBuffer for New Architecture
429+
* TTS Result with ArrayBuffer
504430
*/
505431
export interface TTSBufferResult {
506432
audioBuffer: ArrayBuffer;
@@ -510,8 +436,6 @@ export interface TTSBufferResult {
510436

511437
/**
512438
* TTS Manager for text-to-speech synthesis
513-
*
514-
* Supports both legacy bridge (base64) and JSI (zero-copy ArrayBuffer)
515439
* Note: TTS has a GPL dependency (ESpeakNG) - check license compatibility
516440
*/
517441
export class TTSManager {
@@ -526,31 +450,23 @@ export class TTSManager {
526450
}
527451

528452
/**
529-
* Synthesize text to ArrayBuffer (zero-copy with JSI when available)
453+
* Synthesize text to ArrayBuffer
530454
* @param text Text to synthesize
531455
* @param voice Voice ID to use (optional, uses recommended voice if not specified)
532456
* @returns Audio buffer with metadata
533457
*/
534458
async synthesizeBuffer(text: string, voice?: string): Promise<TTSBufferResult> {
535459
this.ensureInitialized();
536-
537-
if (hasJSI()) {
538-
// Zero-copy path: returns ArrayBuffer directly
539-
return (global as any).FluidAudio_synthesize(text, voice ?? null);
540-
} else {
541-
// Legacy path: convert base64 to ArrayBuffer
542-
const result = await FluidAudioNative.synthesize(text, voice);
543-
return {
544-
audioBuffer: base64ToArrayBuffer(result.audioData),
545-
duration: result.duration,
546-
sampleRate: result.sampleRate,
547-
};
548-
}
460+
const result = await FluidAudioNative.synthesize(text, voice);
461+
return {
462+
audioBuffer: base64ToArrayBuffer(result.audioData),
463+
duration: result.duration,
464+
sampleRate: result.sampleRate,
465+
};
549466
}
550467

551468
/**
552-
* Synthesize text to speech (legacy base64 API)
553-
* @deprecated Use synthesizeBuffer() for better performance
469+
* Synthesize text to speech
554470
* @param text Text to synthesize
555471
* @param voice Voice ID to use (optional, uses recommended voice if not specified)
556472
* @returns Audio data as base64 with metadata
@@ -602,7 +518,7 @@ export async function cleanup(): Promise<void> {
602518
// ============================================================================
603519

604520
/**
605-
* Convert ArrayBuffer to base64 string (for legacy bridge fallback)
521+
* Convert ArrayBuffer to base64 string
606522
*/
607523
function arrayBufferToBase64(buffer: ArrayBuffer): string {
608524
const bytes = new Uint8Array(buffer);
@@ -633,8 +549,6 @@ const FluidAudio = {
633549
// System
634550
getSystemInfo,
635551
isAppleSilicon,
636-
isNewArchitecture,
637-
hasZeroCopySupport,
638552

639553
// Managers
640554
ASRManager,

src/NativeFluidAudio.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { TurboModule } from 'react-native';
22
import { TurboModuleRegistry } from 'react-native';
33

4-
// Simplified Codegen spec - legacy bridge methods only
5-
// ArrayBuffer methods are handled via JSI bindings separately
64
export interface Spec extends TurboModule {
75
// System Info
86
getSystemInfo(): Promise<{

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export {
44
// System
55
getSystemInfo,
66
isAppleSilicon,
7-
isNewArchitecture,
8-
hasZeroCopySupport,
97
// Managers
108
ASRManager,
119
StreamingASRManager,

0 commit comments

Comments
 (0)