Skip to content

Commit

Permalink
Update: styleIdの変更に追従
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Jan 20, 2024
1 parent 6d6e670 commit ed6c283
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/mobile/engine/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ const dictProvider: ApiProvider = ({ corePlugin }) => {
return;
},
async importUserDictWordsImportUserDictPost(req) {
if (!req.requestBody) {
// 型によるとnullableらしいので、nullチェックを入れる
throw new Error("assert: requestBody is not null");
}
const dict = await getUserDictWords();
for (const [uuid, word] of Object.entries(req.requestBody)) {
if (dict[uuid] && !req.override) {
Expand Down
59 changes: 48 additions & 11 deletions src/mobile/engine/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {

const queryProvider: ApiProvider = ({ corePlugin }) => {
return {
async audioQueryAudioQueryPost({ text, speaker }) {
async audioQueryAudioQueryPost({ text, speaker, styleId }) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const rawQuery = await corePlugin
.audioQuery({ text, speakerId: speaker })
.audioQuery({ text, speakerId })
.then((res) => JSON.parse(res.value));
return AudioQueryFromJSON({
accent_phrases: rawQuery.accent_phrases,
Expand All @@ -25,38 +29,66 @@ const queryProvider: ApiProvider = ({ corePlugin }) => {
});
},

async accentPhrasesAccentPhrasesPost({ speaker, text }) {
async accentPhrasesAccentPhrasesPost({ speaker, text, styleId }) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const rawAccentPhrases = await corePlugin
.accentPhrases({ text, speakerId: speaker })
.accentPhrases({ text, speakerId })
.then((res) => JSON.parse(res.value));
return rawAccentPhrases.map(AccentPhraseFromJSON);
},

async moraLengthMoraLengthPost({ accentPhrase: accentPhrases, speaker }) {
async moraLengthMoraLengthPost({
accentPhrase: accentPhrases,
speaker,
styleId,
}) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const rawMoraLength = await corePlugin
.phonemeLength({
accentPhrases: JSON.stringify(accentPhrases.map(AccentPhraseToJSON)),
speakerId: speaker,
speakerId,
})
.then((res) => JSON.parse(res.value));
return rawMoraLength.map(AccentPhraseFromJSON);
},

async moraPitchMoraPitchPost({ accentPhrase: accentPhrases, speaker }) {
async moraPitchMoraPitchPost({
accentPhrase: accentPhrases,
speaker,
styleId,
}) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const rawMoraPitch = await corePlugin
.moraPitch({
accentPhrases: JSON.stringify(accentPhrases.map(AccentPhraseToJSON)),
speakerId: speaker,
speakerId,
})
.then((res) => JSON.parse(res.value));
return rawMoraPitch.map(AccentPhraseFromJSON);
},

async moraDataMoraDataPost({ accentPhrase: accentPhrases, speaker }) {
async moraDataMoraDataPost({
accentPhrase: accentPhrases,
speaker,
styleId,
}) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const rawMoraData = await corePlugin
.moraData({
accentPhrases: JSON.stringify(accentPhrases.map(AccentPhraseToJSON)),
speakerId: speaker,
speakerId,
})
.then((res) => JSON.parse(res.value));
return rawMoraData.map(AccentPhraseFromJSON);
Expand All @@ -65,8 +97,13 @@ const queryProvider: ApiProvider = ({ corePlugin }) => {
async synthesisSynthesisPost({
audioQuery,
speaker,
styleId,
enableInterrogativeUpspeak,
}) {
const speakerId = speaker ?? styleId;
if (!speakerId) {
throw new Error("speakerIdが指定されていません");
}
const b64Audio = await corePlugin
.synthesis({
audioQuery: JSON.stringify({
Expand All @@ -81,7 +118,7 @@ const queryProvider: ApiProvider = ({ corePlugin }) => {
output_stereo: audioQuery.outputStereo,
kana: audioQuery.kana,
}),
speakerId: speaker,
speakerId,
enableInterrogativeUpspeak: !!enableInterrogativeUpspeak,
})
.then((res) => {
Expand Down

0 comments on commit ed6c283

Please sign in to comment.