-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style-Bert-VITS2の設定更新 #158
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,40 +30,85 @@ export default async function handler( | |
const message = body.message | ||
const stylebertvits2ModelId = body.stylebertvits2ModelId | ||
const stylebertvits2ServerUrl = body.stylebertvits2ServerUrl | ||
const stylebertvits2ApiKey = body.stylebertvits2ApiKey | ||
const stylebertvits2Style = body.stylebertvits2Style | ||
const stylebertvits2SdpRatio = body.stylebertvits2SdpRatio | ||
const stylebertvits2Length = body.stylebertvits2Length | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
これらのパラメータに対して、適切な範囲のバリデーションを追加することを検討してください。 |
||
const selectLanguage = getLanguageCode(body.selectLanguage) | ||
|
||
const queryParams = new URLSearchParams({ | ||
text: message, | ||
model_id: stylebertvits2ModelId, | ||
style: stylebertvits2Style, | ||
language: selectLanguage, | ||
}) | ||
|
||
try { | ||
const voice = await fetch( | ||
`${stylebertvits2ServerUrl.replace(/\/$/, '')}/voice?${queryParams}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'audio/wav', | ||
}, | ||
if (!stylebertvits2ServerUrl.includes('https://api.runpod.ai')) { | ||
const queryParams = new URLSearchParams({ | ||
text: message, | ||
model_id: stylebertvits2ModelId, | ||
style: stylebertvits2Style, | ||
sdp_ratio: stylebertvits2SdpRatio, | ||
length: stylebertvits2Length, | ||
language: selectLanguage, | ||
}) | ||
|
||
const voice = await fetch( | ||
`${stylebertvits2ServerUrl.replace(/\/$/, '')}/voice?${queryParams}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'audio/wav', | ||
}, | ||
} | ||
) | ||
|
||
if (!voice.ok) { | ||
throw new Error( | ||
`サーバーからの応答が異常です。ステータスコード: ${voice.status}` | ||
) | ||
} | ||
) | ||
|
||
if (!voice.ok) { | ||
throw new Error( | ||
`サーバーからの応答が異常です。ステータスコード: ${voice.status}` | ||
const arrayBuffer = await voice.arrayBuffer() | ||
const buffer = Buffer.from(arrayBuffer) | ||
res.writeHead(200, { | ||
'Content-Type': 'audio/wav', | ||
'Content-Length': buffer.length, | ||
}) | ||
res.end(buffer) | ||
} else { | ||
const voice = await fetch( | ||
`${stylebertvits2ServerUrl.replace(/\/$/, '')}`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${stylebertvits2ApiKey}`, | ||
}, | ||
body: JSON.stringify({ | ||
input: { | ||
action: '/voice', | ||
model_id: stylebertvits2ModelId, | ||
text: message, | ||
style: stylebertvits2Style, | ||
sdp_ratio: stylebertvits2SdpRatio, | ||
length: stylebertvits2Length, | ||
language: selectLanguage, | ||
}, | ||
}), | ||
} | ||
) | ||
} | ||
|
||
const arrayBuffer = await voice.arrayBuffer() | ||
const buffer = Buffer.from(arrayBuffer) | ||
res.writeHead(200, { | ||
'Content-Type': 'audio/wav', | ||
'Content-Length': buffer.length, | ||
}) | ||
res.end(buffer) | ||
if (!voice.ok) { | ||
throw new Error( | ||
`サーバーからの応答が異常です。ステータスコード: ${voice.status}` | ||
) | ||
} | ||
|
||
const voiceData = await voice.json() | ||
const base64Audio = voiceData.output.voice | ||
const buffer = Buffer.from(base64Audio, 'base64') | ||
|
||
res.writeHead(200, { | ||
'Content-Type': 'audio/wav', | ||
'Content-Length': buffer.length, | ||
}) | ||
res.end(buffer) | ||
} | ||
} catch (error: any) { | ||
res.status(500).json({ error: error.message }) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APIキーのバリデーションを追加することを検討してください。
APIキーは機密情報であり、ログやエラーメッセージに含めるべきではありません。また、APIキーが存在し、期待されるフォーマットであることを確認するためのバリデーションを追加することをお勧めします。