Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Alexander
/
alex-hunter-sales-dev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a1b08947
authored
Dec 04, 2022
by
Nick N. Sukharev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Обновлена версия модуля customTts.js до шаблонной
1 parent
ccfca291
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
65 deletions
customTts.js
customTts.js
View file @
a1b0894
...
...
@@ -3,79 +3,83 @@ const path = require("path");
class
AudioResources
{
constructor
()
{
this
.
resources
=
{};
}
constructor
()
{
this
.
resources
=
{};
}
getResourceKey
(
text
,
voiceInfo
)
{
return
[
voiceInfo
.
lang
??
""
,
voiceInfo
.
speaker
??
""
,
voiceInfo
.
emotion
??
"Neutral"
,
voiceInfo
.
speed
??
1
,
voiceInfo
.
variation
??
0
,
text
,
].
join
(
"|"
);
}
getResourceKey
(
text
,
voiceInfo
)
{
return
[
voiceInfo
.
lang
??
""
,
voiceInfo
.
speaker
??
""
,
voiceInfo
.
emotion
??
"Neutral"
,
voiceInfo
.
speed
??
1
,
voiceInfo
.
variation
??
0
,
text
,
].
join
(
"|"
);
}
async
appendJson
(
folder
,
pack
)
{
const
errors
=
[];
let
i
=
0
;
for
(
const
phrase
of
pack
.
phrases
??
[])
{
i
++
;
// валидация
if
(
phrase
.
phrase
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'phrase' is undefined`
);
continue
;
}
if
(
phrase
.
audio
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'audio' is undefined`
);
continue
;
}
const
audioFile
=
path
.
join
(
folder
,
phrase
.
audio
);
if
(
!
fs
.
existsSync
(
audioFile
))
{
errors
.
push
(
`For
${
i
}
phrase "
${
phrase
.
phrase
}
" file not found`
);
continue
;
}
phrase
.
voice
=
{
...
pack
.
voice
,
...
phrase
.
voice
};
const
resourceKey
=
this
.
getResourceKey
(
phrase
.
phrase
,
phrase
.
voice
??
{});
if
(
resourceKey
in
this
.
resources
)
{
// дубликат - не ошибка
console
.
warn
(
"Skip"
,
i
,
"phrase because it's duplicate"
);
continue
;
}
this
.
resources
[
resourceKey
]
=
audioFile
;
}
if
(
errors
.
length
>
0
)
{
console
.
error
(
`Was errors
${
JSON
.
stringify
(
errors
)}
`
)
}
async
appendJson
(
folder
,
pack
)
{
const
errors
=
[];
let
i
=
0
;
for
(
const
phrase
of
pack
.
phrases
??
[])
{
i
++
;
// валидация
if
(
phrase
.
phrase
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'phrase' is undefined`
);
continue
;
}
if
(
phrase
.
audio
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'audio' is undefined`
);
continue
;
}
const
audioFile
=
path
.
join
(
folder
,
phrase
.
audio
);
if
(
!
fs
.
existsSync
(
audioFile
))
{
errors
.
push
(
`For
${
i
}
phrase '
${
phrase
.
phrase
}
' file not found`
);
continue
;
}
phrase
.
voice
=
{
...
pack
.
voice
,
...
phrase
.
voice
};
const
resourceKey
=
this
.
getResourceKey
(
phrase
.
phrase
,
phrase
.
voice
??
{});
if
(
resourceKey
in
this
.
resources
)
{
// дубликат - не ошибка
console
.
warn
(
"Skip"
,
i
,
"phrase because it's duplicate"
);
continue
;
}
this
.
resources
[
resourceKey
]
=
audioFile
;
}
async
addFolder
(
folder
)
if
(
errors
.
length
>
0
)
{
const
files
=
fs
.
readdirSync
(
folder
);
for
(
const
fileName
of
files
)
{
if
(
path
.
extname
(
fileName
)
===
".json"
)
{
const
fname
=
path
.
join
(
folder
,
fileName
);
console
.
log
(
`Parsing
${
fname
}
`
);
await
this
.
appendJson
(
folder
,
JSON
.
parse
(
fs
.
readFileSync
(
fname
).
toString
()));
}
}
console
.
error
(
`Was errors:
${
JSON
.
stringify
(
errors
,
undefined
,
2
)}
`
);
return
false
;
}
return
true
;
}
GetPath
(
text
,
voiceInfo
)
async
addFolder
(
folder
)
{
const
files
=
fs
.
readdirSync
(
folder
);
let
result
=
false
;
for
(
const
fileName
of
files
)
{
const
key
=
this
.
getResourceKey
(
text
,
voiceInfo
);
const
fpath
=
this
.
resources
[
key
];
if
(
fpath
===
undefined
)
throw
new
Error
(
`Failed to get
${
key
}
`
);
return
fpath
;
if
(
path
.
extname
(
fileName
)
===
".json"
)
{
const
fname
=
path
.
join
(
folder
,
fileName
);
console
.
log
(
`Parsing
${
fname
}
`
);
result
=
await
this
.
appendJson
(
folder
,
JSON
.
parse
(
fs
.
readFileSync
(
fname
).
toString
()));
}
}
return
result
;
}
GetPath
(
text
,
voiceInfo
)
{
const
key
=
this
.
getResourceKey
(
text
,
voiceInfo
);
const
fpath
=
this
.
resources
[
key
];
if
(
fpath
===
undefined
)
throw
new
Error
(
`Failed to get
${
key
}
`
);
return
fpath
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment