PDF 朗读的逐词回调会在同一页内持续触发高亮,原实现每次都调用翻页入口,使用户在朗读过程中反复看到页面转场。现仅在目标页变化时定位,并对朗读产生的跨页定位禁用动画,保留高亮刷新而不重复翻页。\n\nEPUB/TXT 此前只提供内容源,缺少将朗读进度回写到阅读器的会话层,无法从当前阅读位置开始朗读、随内容跨页及显示临时高亮。新增 EPUB 朗读会话,使用 href 与 UTF-16 偏移恢复位置;文本重排 EPUB 与 TXT 按实际页面定位并高亮,Web EPUB 则按章节安全定位以避免词级回调导致跳页。URL 阅读器同时提供可选会话入口,图片型阅读器保持不可朗读。\n\n已执行 ReadViewDemo 的 Debug Simulator 构建,结果为 BUILD SUCCEEDED。
47 lines
1.3 KiB
Markdown
47 lines
1.3 KiB
Markdown
# RDSpeechReaderView
|
|
|
|
`RDSpeechReaderView` provides bounded, on-device text-to-speech playback for
|
|
ReadViewSDK readers. It uses `AVSpeechSynthesizer` and does not upload book
|
|
content or create exportable audio files.
|
|
|
|
## Install
|
|
|
|
```ruby
|
|
pod 'RDSpeechReaderView'
|
|
pod 'RDPDFReaderView/Speech'
|
|
pod 'RDEpubReaderView/Speech'
|
|
```
|
|
|
|
The host app must enable the **Audio, AirPlay, and Picture in Picture**
|
|
background mode to continue reading after it enters the background.
|
|
|
|
## Use with PDF
|
|
|
|
```swift
|
|
let provider = reader.makeSpeechContentProvider()
|
|
let speech = RDSpeechReaderController(contentProvider: provider)
|
|
try await speech.start()
|
|
```
|
|
|
|
The PDF adapter reads `RDPDFReaderTextRun` values supplied by the host or by
|
|
PDFKit. Image-only PDFs require an OCR-backed provider before they can speak.
|
|
|
|
For automatic page navigation and temporary read-aloud highlighting, create a
|
|
PDF session instead:
|
|
|
|
```swift
|
|
let session = reader.makeSpeechSession()
|
|
try await session.start(from: 0)
|
|
```
|
|
|
|
## Use with EPUB
|
|
|
|
```swift
|
|
let session = reader.makeSpeechSession()
|
|
try await session.start()
|
|
```
|
|
|
|
EPUB/TXT 会话默认从当前阅读位置开始。文本重排 EPUB 与 TXT 会临时高亮当前朗读范围,
|
|
并且只在朗读跨页时定位;朗读位置使用 EPUB `href` 与 UTF-16 文本偏移,因此用户修改
|
|
字体或页面大小后仍可稳定恢复。
|