Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
98c564f4
Commit
98c564f4
authored
1 year ago
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pref: 优化语音播报断句
parent
ce5c9c28
Pipeline
#87201
waiting for manual action with stages
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
20 deletions
+40
-20
config.js
src/components/SoundAi/core/config.js
+2
-1
index.js
...nents/SoundAi/core/core/SpeechSynthesisUtterance/index.js
+33
-14
index.js
...onents/SoundAi/core/directive/CloseMenuDirective/index.js
+3
-3
CloseSessionDirective.js
...omponents/SoundAi/core/directive/CloseSessionDirective.js
+1
-1
index.js
...ponents/SoundAi/core/directive/OpenMenuDirective/index.js
+1
-1
No files found.
src/components/SoundAi/core/config.js
View file @
98c564f4
export
default
{
punctuationMark
:
"。,、;:?!”“,.!:"
punctuationMark
:
new
Set
(
Array
.
from
([
"。"
,
","
,
"、"
,
":"
,
";"
,
"?"
,
"!"
,
"”"
,
"“"
,
","
,
"."
,
"!"
,
":"
,
"
\"
"
,
"
\
n"
]))
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/core/SpeechSynthesisUtterance/index.js
View file @
98c564f4
import
config
from
"../../config"
class
PandaSpeechSynthesisUtterance
{
constructor
(
options
=
{})
{
constructor
(
options
=
{})
{
this
.
voiceParams
=
this
.
getVoiceParams
(
options
.
voiceParams
??
{})
this
.
data
=
[]
window
.
speechSynthesis
.
cancel
()
this
.
resolve
=
null
this
.
reject
=
null
this
.
onEnd
=
this
.
onEnd
.
bind
(
this
)
this
.
tempText
=
""
this
.
punctuationMark
=
Array
.
from
(
config
.
punctuationMark
)
}
getVoiceParams
(
voiceParams
)
{
getVoiceParams
(
voiceParams
)
{
return
{
volume
:
1
,
rate
:
1
,
pitch
:
1
,
volume
:
1
,
rate
:
1
,
pitch
:
1
,
...
voiceParams
}
}
push
(
text
)
{
if
(
!
text
)
return
this
.
data
.
push
(
this
.
getSpeechSynthesisUtterance
(
text
))
window
.
speechSynthesis
.
speak
(
this
.
data
.
at
(
-
1
))
if
(
!
text
)
return
this
.
tempText
+=
text
;
const
match
=
this
.
tempText
.
matchAll
(
new
RegExp
(
`[
${
this
.
punctuationMark
.
join
(
"|"
)}
]`
,
"g"
))
if
(
!
match
)
return
let
startIndex
=
0
,
endIndex
=
0
for
(
const
result
of
match
)
{
startIndex
=
endIndex
endIndex
=
result
.
index
+
1
const
sentence
=
this
.
tempText
.
substring
(
startIndex
,
endIndex
)
this
.
data
.
push
(
this
.
getSpeechSynthesisUtterance
(
sentence
))
window
.
speechSynthesis
.
speak
(
this
.
data
.
at
(
-
1
))
}
this
.
tempText
=
this
.
tempText
.
substring
(
endIndex
)
}
getSpeechSynthesisUtterance
(
text
)
{
const
speak
=
new
SpeechSynthesisUtterance
(
text
)
speak
.
addEventListener
(
"end"
,
this
.
onEnd
)
for
(
let
key
in
this
.
voiceParams
)
{
for
(
let
key
in
this
.
voiceParams
)
{
speak
[
key
]
=
this
.
voiceParams
[
key
]
}
return
speak
}
onEnd
()
{
onEnd
()
{
this
.
data
.
shift
()
if
(
this
.
data
.
length
==
0
)
{
if
(
this
.
data
.
length
==
0
)
{
this
.
resolve
&&
this
.
resolve
()
}
}
}
speakEnd
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
speakEnd
()
{
if
(
this
.
tempText
)
{
this
.
data
.
push
(
this
.
getSpeechSynthesisUtterance
(
this
.
tempText
))
window
.
speechSynthesis
.
speak
(
this
.
data
.
at
(
-
1
))
this
.
tempText
=
""
}
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
resolve
=
resolve
this
.
reject
=
reject
})
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/CloseMenuDirective/index.js
View file @
98c564f4
...
...
@@ -10,16 +10,16 @@ class CloseMenuDirective extends BaseDirective {
const
{
text
}
=
this
;
let
result
=
null
;
if
(
!
result
)
{
result
=
text
.
match
(
new
RegExp
(
`关闭(所有).*(?=(?:[
${
config
.
punctuationMark
}
]?))`
))
result
=
text
.
match
(
new
RegExp
(
`关闭(所有).*(?=(?:[
${
Array
.
from
(
config
.
punctuationMark
).
join
(
"|"
)
}
]?))`
))
}
if
(
!
result
)
{
result
=
text
.
match
(
new
RegExp
(
`关闭(当前).*(?=(?:[
${
config
.
punctuationMark
}
]?))`
))
result
=
text
.
match
(
new
RegExp
(
`关闭(当前).*(?=(?:[
${
Array
.
from
(
config
.
punctuationMark
).
join
(
"|"
)
}
]?))`
))
}
if
(
!
result
)
{
result
=
text
.
match
(
/关闭
(
.*
)(?=(?:
菜单|功能|路径
))
/
);
}
if
(
!
result
)
{
result
=
text
.
match
(
new
RegExp
(
`关闭(.*)(?=(?:[
${
config
.
punctuationMark
}
]?))`
))
result
=
text
.
match
(
new
RegExp
(
`关闭(.*)(?=(?:[
${
Array
.
from
(
config
.
punctuationMark
).
join
(
"|"
)
}
]?))`
))
}
if
(
result
&&
result
.
length
>=
2
&&
!
this
.
matchResult
)
{
this
.
matchResult
=
result
[
1
];
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/CloseSessionDirective.js
View file @
98c564f4
...
...
@@ -3,7 +3,7 @@ import BaseDirective from './BaseDirective'
class
CloseSessionDirective
extends
BaseDirective
{
match
(){
const
{
text
}
=
this
if
(
/
结束
(
.*
)[
的对
]
话
/
.
test
(
text
))
{
if
(
/
[
熊猫熊猫|什么什么
]
/
.
test
(
text
))
{
return
true
}
return
false
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/OpenMenuDirective/index.js
View file @
98c564f4
...
...
@@ -15,7 +15,7 @@ class OpenMenuDirective extends BaseDirective {
result
=
text
.
match
(
/打开
(
.*
)(?=(?:
菜单|功能|路径
))
/
)
}
if
(
!
result
)
{
result
=
text
.
match
(
new
RegExp
(
`打开(.*)(?=(?:[
${
config
.
punctuationMark
}
]?))`
))
result
=
text
.
match
(
new
RegExp
(
`打开(.*)(?=(?:[
${
Array
.
from
(
config
.
punctuationMark
).
join
(
"|"
)
}
]?))`
))
}
if
(
result
&&
result
.
length
>=
2
&&
!
this
.
matchResult
)
{
this
.
matchResult
=
result
[
1
]
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment