Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CharIP-Electron
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
ali
CharIP-Electron
Commits
7456d071
You need to sign in or sign up before continuing.
Commit
7456d071
authored
Dec 04, 2023
by
ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 照片数字人语音播放
parent
76e086cc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
6 deletions
+44
-6
FetchTTS.ts
src/renderer/plugins/tts/FetchTTS.ts
+12
-2
ShowPhoto.vue
src/renderer/screens/ShowPhoto.vue
+32
-4
No files found.
src/renderer/plugins/tts/FetchTTS.ts
View file @
7456d071
/* eslint-disable camelcase */
export
async
function
audioAiTTS
({
host
,
text
,
...
...
@@ -35,14 +36,23 @@ export async function audioAiTTS({
return
res
.
data
}
export
async
function
localTTS
({
url
,
text
}:
{
url
:
string
;
text
:
string
})
{
export
async
function
localTTS
({
url
,
text
,
audio_path
}:
{
url
:
string
text
:
string
audio_path
?:
string
})
{
const
resp
=
await
fetch
(
url
,
{
headers
:
{
accept
:
'application/json, text/plain, */*'
,
'content-type'
:
'application/json'
},
body
:
JSON
.
stringify
({
text
text
,
audio_path
}),
method
:
'POST'
,
mode
:
'cors'
...
...
src/renderer/screens/ShowPhoto.vue
View file @
7456d071
...
...
@@ -247,6 +247,8 @@ function endAudioInput() {
}
async
function
onAsr
(
question
:
string
)
{
console
.
log
(
'---------------->question: '
,
question
);
endAudioInput
();
const
ws
=
await
initSocket
()
inputContext
.
ws
=
ws
...
...
@@ -264,6 +266,10 @@ async function onAsr(question: string) {
}
if
(
event
===
'stream_end'
)
{
answerArray
.
push
(
sliceAnswer
)
runTTSTask
(
answerArray
)
sliceAnswer
=
''
answerArray
.
push
(
sliceAnswer
)
sliceAnswer
=
''
inputContext
.
ws
?.
close
()
...
...
@@ -301,7 +307,6 @@ function initSocket(): Promise<WebSocket> {
}
let
isTTSRunning
=
false
const
ttsAudios
:
HTMLAudioElement
[]
=
[]
async
function
runTTSTask
(
tasks
:
string
[])
{
if
(
isTTSRunning
)
return
isTTSRunning
=
true
...
...
@@ -310,11 +315,16 @@ async function runTTSTask(tasks: string[]) {
while
(
tasks
.
length
)
{
const
task
=
tasks
.
shift
()
if
(
!
task
)
break
if
(
task
.
length
<
1
)
continue
;
console
.
time
(
task
+
' TTS: '
)
const
res
=
await
localTTS
({
url
:
settings
.
ttsHost
,
text
:
task
})
console
.
log
(
'----------------> TTS:'
,
res
)
const
res
=
await
localTTS
({
url
:
settings
.
ttsHost
,
text
:
task
,
audio_path
:
settings
.
userData
})
console
.
log
(
'----------------> TTS:'
,
res
[
0
].
text
)
console
.
timeEnd
(
task
+
' TTS: '
)
console
.
log
(
'---------------->'
,
ttsAudios
)
const
audio
=
new
Audio
(
`file://
${
res
[
0
].
text
}
`
);
audio
.
load
();
ttsAudios
.
push
(
audio
);
runAudioPlay
();
}
}
catch
(
error
)
{
console
.
error
(
error
)
...
...
@@ -323,6 +333,24 @@ async function runTTSTask(tasks: string[]) {
isTTSRunning
=
false
}
const
ttsAudios
:
HTMLAudioElement
[]
=
[]
let
isPlayRunning
=
false
async
function
runAudioPlay
()
{
if
(
isPlayRunning
)
return
isPlayRunning
=
true
const
audio
=
ttsAudios
.
shift
();
if
(
!
audio
)
{
isPlayRunning
=
false
;
return
;
}
audio
.
onended
=
()
=>
{
isPlayRunning
=
false
;
runAudioPlay
()
};
await
audio
.
play
();
}
// eslint-disable-next-line no-unused-vars
async
function
xfTTS
(
text
:
string
)
{
const
tone
=
settings
.
source
.
find
(({
sourceId
})
=>
settings
.
selectSource
===
sourceId
)
...
...
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