Fix TTS might stop at the end of the section (#126)
This commit is contained in:
@@ -23,6 +23,7 @@ import { useFoliateEvents } from '../../hooks/useFoliateEvents';
|
||||
import { useNotesSync } from '../../hooks/useNotesSync';
|
||||
import { getPopupPosition, getPosition, Position, TextSelection } from '@/utils/sel';
|
||||
import { eventDispatcher } from '@/utils/event';
|
||||
import { getBookLangCode } from '@/utils/book';
|
||||
import AnnotationPopup from './AnnotationPopup';
|
||||
import WiktionaryPopup from './WiktionaryPopup';
|
||||
import WikipediaPopup from './WikipediaPopup';
|
||||
@@ -339,7 +340,9 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => {
|
||||
if (!selection || !selection.text) return;
|
||||
setShowAnnotPopup(false);
|
||||
|
||||
await view!.initTTS();
|
||||
const lang = getBookLangCode(bookData.bookDoc!.metadata.language);
|
||||
const granularity = ['zh', 'ja', 'ko'].includes(lang) ? 'sentence' : 'word';
|
||||
await view!.initTTS(granularity);
|
||||
const ssml = view!.tts.from(selection.range)!;
|
||||
eventDispatcher.dispatch('speak', { bookKey, ssml });
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@ import { BookDoc } from '@/libs/document';
|
||||
import { BookNote, BookSearchConfig, BookSearchResult } from '@/types/book';
|
||||
import { TTS } from 'foliate-js/tts.js';
|
||||
|
||||
type TTSGranularity = 'sentence' | 'word';
|
||||
|
||||
export interface FoliateView extends HTMLElement {
|
||||
open: (book: BookDoc) => Promise<void>;
|
||||
close: () => void;
|
||||
@@ -18,7 +20,7 @@ export interface FoliateView extends HTMLElement {
|
||||
clearSearch: () => void;
|
||||
select: (target: string | number | { fraction: number }) => void;
|
||||
deselect: () => void;
|
||||
initTTS: () => Promise<void>;
|
||||
initTTS: (granularity?: TTSGranularity) => Promise<void>;
|
||||
tts: TTS;
|
||||
history: {
|
||||
canGoBack: boolean;
|
||||
|
||||
+1
-1
Submodule packages/foliate-js updated: aa5f950b1f...238fbc216c
Reference in New Issue
Block a user