ローカルで日本語を発話するようになった

This commit is contained in:
Akira
2026-03-03 12:37:26 +09:00
parent fe9ee0147c
commit 07258bb46d
5 changed files with 175 additions and 23 deletions

View File

@@ -130,31 +130,35 @@ app.post('/speak', async function(req, res) {
console.log(' -> ' + target.accountName + ' (type=' + target.deviceType + ', serial=' + target.serialNumber + ')');
// locale: '' はローカルPCでは日本語発話成功サーバーからは要検証
// Alexa.SpeakSsml 系は全滅のため Alexa.Speak に戻す
var sequenceObj = {
'@type': 'com.amazon.alexa.behaviors.model.Sequence',
startNode: {
'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode',
type: 'Alexa.Speak',
operationPayload: {
deviceType: target.deviceType,
deviceSerialNumber: target.serialNumber,
customerId: customerId,
locale: '',
textToSpeak: text
},
},
};
// ★ 重要: sequenceJson の non-ASCII日本語等を \uXXXX エスケープに変換してから送る
// raw UTF-8 のまま送ると Amazon 側でフィルタリングされ日本語が発話されない(解決済み 2026-03-03
var sequenceObj = {
'@type': 'com.amazon.alexa.behaviors.model.Sequence',
startNode: {
'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode',
type: 'Alexa.Speak',
operationPayload: {
deviceType: target.deviceType,
deviceSerialNumber: target.serialNumber,
customerId: customerId,
locale: 'ja-JP',
textToSpeak: text
},
},
};
var rawSequenceJson = JSON.stringify(sequenceObj).replace(
/[\u0080-\uffff]/g,
function(c) { return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4); }
);
var bodyStr = JSON.stringify({
behaviorId: 'PREVIEW',
sequenceJson: JSON.stringify(sequenceObj),
sequenceJson: rawSequenceJson,
status: 'ENABLED',
});
// リクエストボディをログ出力(認証・パラメータ確認用)
console.log('[DEBUG] sequenceJson:', JSON.stringify(sequenceObj, null, 2));
console.log('[DEBUG] textToSpeak:', text);
var ttsRes = await httpsRequest('/api/behaviors/preview', {
method: 'POST',