Splits article content into smaller audio segments. This allows for more granular control over playback, faster processing, and improved user experience by enabling auto-scrolling to the currently read segment. Updates `types.ts` to include `AudioSegment` interface and modify `Article` to hold `segments`, `currentSegmentIndex`, and `audioUrl` per segment. Introduces `segmentText` utility in `services/textUtils.ts` for robust text segmentation logic. Modifies `App.tsx` to utilize the new segmentation approach for fetching and processing audio. Enhances `components/ReaderView.tsx` to display and auto-scroll through segmented text, highlighting the current segment during playback.
48 lines
967 B
TypeScript
48 lines
967 B
TypeScript
|
|
export enum VoiceName {
|
|
Puck = 'Puck',
|
|
Charon = 'Charon',
|
|
Kore = 'Kore',
|
|
Fenrir = 'Fenrir',
|
|
Zephyr = 'Zephyr',
|
|
}
|
|
|
|
export enum PlaybackStatus {
|
|
IDLE = 'IDLE',
|
|
LOADING_TEXT = 'LOADING_TEXT',
|
|
LOADING_AUDIO = 'LOADING_AUDIO',
|
|
READY = 'READY',
|
|
PLAYING = 'PLAYING',
|
|
PAUSED = 'PAUSED',
|
|
ERROR = 'ERROR',
|
|
COMPLETED = 'COMPLETED'
|
|
}
|
|
|
|
export interface AudioSegment {
|
|
id: string;
|
|
text: string;
|
|
audioUrl?: string; // Blob URL for this specific segment
|
|
isLoading: boolean;
|
|
hasError: boolean;
|
|
}
|
|
|
|
export interface Article {
|
|
id: string;
|
|
url: string;
|
|
title: string;
|
|
// We keep the full text for display/reference
|
|
text: string;
|
|
// We split content into segments for faster playback
|
|
segments: AudioSegment[];
|
|
currentSegmentIndex: number;
|
|
status: PlaybackStatus;
|
|
errorMessage?: string;
|
|
}
|
|
|
|
export interface PlayerState {
|
|
isPlaying: boolean;
|
|
playbackRate: number;
|
|
currentArticleId: string | null;
|
|
selectedVoice: VoiceName;
|
|
}
|