fix(speech): write native TTS temp file as binary and clean it up
App-Plus 的 plus.io FileWriter 只接受字符串:write 写文本,writeAsBinary 收
base64。原先传 Blob 会被原生桥接序列化成空内容,落地 0 字节且照样回调
onwriteend,InnerAudioContext 静默播完、不报错,表现为"界面正常但没有声音"。
改用 writeAsBinary 并在 onwriteend 里复核 size > 0,让写盘失败能被暴露。
清理侧同一处存在文件泄漏:播放要 convertLocalFileSystemURL 转出的 file://
绝对路径,而 resolveLocalFileSystemURL 删除只认 `_doc/xxx.mp3` 相对路径。
原先只回传前者,拿它去 resolve 解析不到,remove() 从不执行,且 catch 静默,
临时 mp3 逐句堆积。改为返回 { playbackUrl, plusPath } 两个路径,清理失败加告警。
真机验证(Android 10 / io.dcloud.HBuilder):落盘 80251 字节,ID3+LAME 头,
MPEG layer III 160 kbps 24 kHz 单声道,播完文件自动删除。
顺带把测试里 MP3 头字面量的真实 NUL 字节改为 \x00 转义(运行时字节不变),
此前 git 将该测试文件判为二进制,diff 无法审阅。
This commit is contained in:
@@ -245,16 +245,16 @@ export const createSpeechPlaybackController = (
|
||||
// webview 也常静默失败,统一先转换:H5 转 Blob URL,App 端落临时文件。
|
||||
if (isDataAudioUri(source)) {
|
||||
if (hasNativeAudioFileSupport()) {
|
||||
void writeNativeTempAudio(source).then((fileUrl) => {
|
||||
if (!fileUrl) {
|
||||
void writeNativeTempAudio(source).then((temp) => {
|
||||
if (!temp) {
|
||||
failPlayback();
|
||||
return;
|
||||
}
|
||||
if (!isActivePlayback()) {
|
||||
removeNativeTempAudio(fileUrl);
|
||||
removeNativeTempAudio(temp.plusPath);
|
||||
return;
|
||||
}
|
||||
startPlayback(fileUrl, () => removeNativeTempAudio(fileUrl));
|
||||
startPlayback(temp.playbackUrl, () => removeNativeTempAudio(temp.plusPath));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user