Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
aivoice_plugin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王苏进
aivoice_plugin
Commits
83ea0d07
提交
83ea0d07
authored
9月 13, 2024
作者:
王苏进
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 增加 同步语音文字显示
上级
f9defa05
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
34 行删除
+23
-34
main.dart
example/lib/main.dart
+3
-1
TtsNovel.m
ios/Classes/TtsNovel.m
+20
-33
没有找到文件。
example/lib/main.dart
浏览文件 @
83ea0d07
...
...
@@ -35,8 +35,10 @@ class _MyAppState extends State<MyApp> {
_aivoicePlugin
.
onAsrResultReceived
.
listen
((
event
)
{
final
a
=
event
[
"finish"
];
final
b
=
event
[
"playWords"
];
setState
(()
{});
_text
=
"
$a
"
;
_text
=
b
??
"
$a
"
;
// print(event["text"]);
});
_aivoicePlugin
.
prepareEnvironment
({
"appId"
:
"2301072440"
});
...
...
ios/Classes/TtsNovel.m
浏览文件 @
83ea0d07
...
...
@@ -692,12 +692,8 @@ static int TTS_MAX_RETRY_COUNT = 3;
// 根据 SDK 返回的播放进度高亮正在播放的文本,用红色表示
// 根据 SDK 返回的合成开始和合成结束回调高亮正在合成的文本,用蓝色表示
-
(
void
)
updateTtsResultText
:
(
NSString
*
)
playingId
{
if
(
self
.
engineErrorOccurred
)
{
NSLog
(
@"When a fatal error occurs, prevent the playback text from being displayed."
);
return
;
}
-
(
void
)
updatePlayingWords
:
(
NSString
*
)
playingId
{
int
synthesisIndex
=
self
.
ttsSynthesisIndex
;
NSNumber
*
val
=
[
self
.
ttsSynthesisMap
objectForKey
:
playingId
];
if
(
val
!=
nil
)
{
self
.
ttsPlayingIndex
=
[
val
intValue
];
...
...
@@ -705,7 +701,8 @@ static int TTS_MAX_RETRY_COUNT = 3;
int
beginIndex
=
MAX
(
self
.
ttsPlayingIndex
,
0
);
int
maxSentencesDisplayed
=
MIN
((
int
)[
self
.
ttsSynthesisText
count
],
16
);
NSMutableAttributedString
*
resultStr
=
[[
NSMutableAttributedString
alloc
]
initWithString
:
@""
];
NSString
*
resultStr
=
@""
;
for
(
int
cnt
=
0
;
cnt
<
maxSentencesDisplayed
;
++
cnt
)
{
int
index
=
(
beginIndex
+
cnt
)
%
[
self
.
ttsSynthesisText
count
];
NSString
*
current_sentence
=
self
.
ttsSynthesisText
[
index
];
...
...
@@ -713,13 +710,11 @@ static int TTS_MAX_RETRY_COUNT = 3;
if
(
index
==
self
.
ttsPlayingIndex
)
{
playedPosition
=
MIN
(
ceil
((
double
)(
self
.
ttsPlayingProgress
)
*
(
double
)([
current_sentence
length
])),
[
current_sentence
length
]);
NSLog
(
@"played position: %ld"
,
(
long
)
playedPosition
);
NSString
*
playedString
=
[
current_sentence
substringToIndex
:
playedPosition
];
NSAttributedString
*
playedSpan
=
[[
NSAttributedString
alloc
]
initWithString
:
playedString
attributes
:[
NSDictionary
dictionaryWithObject
:[
UIColor
redColor
]
forKey
:
NSForegroundColorAttributeName
]];
[
resultStr
appendAttributedString
:
playedSpan
];
resultStr
=
[
resultStr
stringByAppendingString
:[
current_sentence
substringToIndex
:
playedPosition
]];
}
if
([
self
.
delegate
respondsToSelector
:
@selector
(
onRecieve
:)])
{
[
self
.
delegate
onRecieve
:@{
@"playWords"
:
resultStr
}];
}
NSString
*
remainString
=
[
current_sentence
substringFromIndex
:
playedPosition
];
NSAttributedString
*
span
=
[[
NSAttributedString
alloc
]
initWithString
:
remainString
attributes
:[
NSDictionary
dictionaryWithObject
:[
UIColor
blackColor
]
forKey
:
NSForegroundColorAttributeName
]];
[
resultStr
appendAttributedString
:
span
];
}
// [self.resultTextView setAttributedText:resultStr];
}
...
...
@@ -749,7 +744,7 @@ static int TTS_MAX_RETRY_COUNT = 3;
dispatch_async
(
dispatch_get_main_queue
(),
^
{
// self.pauseResumeButton.enabled = TRUE;
self
.
ttsPlayingProgress
=
0
.
0
;
[
self
update
TtsResultText
:
playingId
];
[
self
update
PlayingWords
:
playingId
];
});
}
...
...
@@ -771,10 +766,8 @@ static int TTS_MAX_RETRY_COUNT = 3;
NSLog
(
@"playing id: %@, progress in percent: %.2f"
,
reqid
,
percentage
);
dispatch_async
(
dispatch_get_main_queue
(),
^
{
self
.
ttsPlayingProgress
=
percentage
;
if
([
self
.
delegate
respondsToSelector
:
@selector
(
onRecieve
:)])
{
[
self
.
delegate
onRecieve
:@{
@"play_progress"
:
@
(
percentage
)}];
}
// [self updateTtsResultText:reqid];
[
self
updatePlayingWords
:
reqid
];
});
}
}
...
...
@@ -786,26 +779,18 @@ static int TTS_MAX_RETRY_COUNT = 3;
// if (![self.settings getBool:SETTING_TTS_ENABLE_DUMP_NOVEL_TTS_DETAIL]) {
// [self.ttsSynthesisMap removeObjectForKey:playingId];
// }
[
self
.
ttsSynthesisMap
removeObjectForKey
:
playingId
];
dispatch_async
(
dispatch_get_main_queue
(),
^
{
self
.
ttsPlayingProgress
=
1
.
0
;
[
self
updateTtsResultText
:
playingId
];
[
self
updatePlayingWords
:
playingId
];
if
([[
self
.
ttsSynthesisMap
allKeys
]
count
]
==
0
)
{
NSLog
(
@"这里告诉flutter 已经全部读完了"
);
[
self
.
delegate
onRecieve
:@{
@"finish"
:
@
(
YES
)}];
}
});
if
(
self
.
ttsSynthesisFromPlayer
)
{
if
(
self
.
ttsSynthesisIndex
==
0
)
{
// 播放完第一遍后自动停止
[
self
stopEngineBtnClicked
];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
onRecieve
:)])
{
[
self
.
delegate
onRecieve
:@{
@"finish"
:
@
(
true
)}];
}
}
else
{
[
self
triggerSynthesis
];
self
.
ttsSynthesisFromPlayer
=
FALSE
;
}
}
}
...
...
@@ -827,7 +812,9 @@ static int TTS_MAX_RETRY_COUNT = 3;
-
(
void
)
synthesisNextSentence
{
self
.
ttsSynthesisIndex
=
(
self
.
ttsSynthesisIndex
+
1
)
%
[
self
.
ttsSynthesisText
count
];
if
(
!
self
.
ttsSynthesisFromPlayer
)
{
// 合成最后一条后停止
if
(
!
self
.
ttsSynthesisFromPlayer
&&
(
self
.
ttsSynthesisIndex
+
1
)
<
self
.
ttsSynthesisText
.
count
)
{
[
self
triggerSynthesis
];
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论