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");
...
@@ -3,79 +3,83 @@ const path = require("path");
class
AudioResources
class
AudioResources
{
{
constructor
()
constructor
()
{
{
this
.
resources
=
{};
this
.
resources
=
{};
}
}
getResourceKey
(
text
,
voiceInfo
)
{
getResourceKey
(
text
,
voiceInfo
)
{
return
[
return
[
voiceInfo
.
lang
??
""
,
voiceInfo
.
lang
??
""
,
voiceInfo
.
speaker
??
""
,
voiceInfo
.
speaker
??
""
,
voiceInfo
.
emotion
??
"Neutral"
,
voiceInfo
.
emotion
??
"Neutral"
,
voiceInfo
.
speed
??
1
,
voiceInfo
.
speed
??
1
,
voiceInfo
.
variation
??
0
,
voiceInfo
.
variation
??
0
,
text
,
text
,
].
join
(
"|"
);
].
join
(
"|"
);
}
}
async
appendJson
(
folder
,
pack
)
async
appendJson
(
folder
,
pack
)
{
{
const
errors
=
[];
const
errors
=
[];
let
i
=
0
;
let
i
=
0
;
for
(
const
phrase
of
pack
.
phrases
??
[])
{
for
(
const
phrase
of
pack
.
phrases
??
[])
{
i
++
;
i
++
;
// валидация
// валидация
if
(
phrase
.
phrase
===
undefined
)
{
if
(
phrase
.
phrase
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'phrase' is undefined`
);
errors
.
push
(
`For
${
i
}
phrase field 'phrase' is undefined`
);
continue
;
continue
;
}
}
if
(
phrase
.
audio
===
undefined
)
{
if
(
phrase
.
audio
===
undefined
)
{
errors
.
push
(
`For
${
i
}
phrase field 'audio' is undefined`
);
errors
.
push
(
`For
${
i
}
phrase field 'audio' is undefined`
);
continue
;
continue
;
}
}
const
audioFile
=
path
.
join
(
folder
,
phrase
.
audio
);
const
audioFile
=
path
.
join
(
folder
,
phrase
.
audio
);
if
(
!
fs
.
existsSync
(
audioFile
))
{
if
(
!
fs
.
existsSync
(
audioFile
))
{
errors
.
push
(
`For
${
i
}
phrase "
${
phrase
.
phrase
}
" file not found`
);
errors
.
push
(
`For
${
i
}
phrase '
${
phrase
.
phrase
}
' file not found`
);
continue
;
continue
;
}
}
phrase
.
voice
=
{
...
pack
.
voice
,
...
phrase
.
voice
};
phrase
.
voice
=
{
...
pack
.
voice
,
...
phrase
.
voice
};
const
resourceKey
=
this
.
getResourceKey
(
phrase
.
phrase
,
phrase
.
voice
??
{});
const
resourceKey
=
this
.
getResourceKey
(
phrase
.
phrase
,
phrase
.
voice
??
{});
if
(
resourceKey
in
this
.
resources
)
{
if
(
resourceKey
in
this
.
resources
)
{
// дубликат - не ошибка
// дубликат - не ошибка
console
.
warn
(
"Skip"
,
i
,
"phrase because it's duplicate"
);
console
.
warn
(
"Skip"
,
i
,
"phrase because it's duplicate"
);
continue
;
continue
;
}
}
this
.
resources
[
resourceKey
]
=
audioFile
;
this
.
resources
[
resourceKey
]
=
audioFile
;
}
if
(
errors
.
length
>
0
)
{
console
.
error
(
`Was errors
${
JSON
.
stringify
(
errors
)}
`
)
}
}
}
if
(
errors
.
length
>
0
)
async
addFolder
(
folder
)
{
{
const
files
=
fs
.
readdirSync
(
folder
);
console
.
error
(
`Was errors:
${
JSON
.
stringify
(
errors
,
undefined
,
2
)}
`
);
for
(
const
fileName
of
files
)
return
false
;
{
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
()));
}
}
}
}
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
);
if
(
path
.
extname
(
fileName
)
===
".json"
)
const
fpath
=
this
.
resources
[
key
];
{
if
(
fpath
===
undefined
)
const
fname
=
path
.
join
(
folder
,
fileName
);
throw
new
Error
(
`Failed to get
${
key
}
`
);
console
.
log
(
`Parsing
${
fname
}
`
);
return
fpath
;
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