Skip to content
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

[ソング] ピッチ編集に合わせてボリュームを自動的に更新する #2015

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/openapi/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

225 changes: 148 additions & 77 deletions src/openapi/apis/DefaultApi.ts

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/openapi/models/BodySingFrameVolumeSingFrameVolumePost.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/openapi/models/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 74 additions & 4 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
SequencerEditTarget,
} from "./type";
import { sanitizeFileName } from "./utility";
import { EngineId } from "@/type/preload";
import { EngineId, StyleId } from "@/type/preload";
import { FrameAudioQuery, Note as NoteForRequestToEngine } from "@/openapi";
import { ResultError, getValueOrThrow } from "@/type/result";
import {
Expand Down Expand Up @@ -872,8 +872,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
return foundPhrases;
};

const fetchQuery = async (
engineId: EngineId,
const createNotesForRequestToEngine = (
notes: Note[],
tempos: Tempo[],
tpqn: number,
Expand Down Expand Up @@ -919,6 +918,29 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
lyric: "",
});

return notesForRequestToEngine;
};

const singingTeacherStyleId = StyleId(6000); // TODO: 設定できるようにする

const fetchQuery = async (
engineId: EngineId,
notes: Note[],
tempos: Tempo[],
tpqn: number,
keyRangeAdjustment: number,
frameRate: number,
restDurationSeconds: number,
) => {
const notesForRequestToEngine = createNotesForRequestToEngine(
notes,
tempos,
tpqn,
keyRangeAdjustment,
frameRate,
restDurationSeconds,
);
Comment on lines +935 to +942
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ2回実行してますが、1回実行してその結果を関数に渡す形でも良い気がしました!
もちろんエンジンに投げるスコアが必ず同じならですが。(今のところ必ず同じはず。)


try {
if (!getters.IS_ENGINE_READY(engineId)) {
throw new Error("Engine not ready.");
Expand All @@ -930,7 +952,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
"singFrameAudioQuerySingFrameAudioQueryPost",
)({
score: { notes: notesForRequestToEngine },
speaker: 6000, // TODO: 設定できるようにする
speaker: singingTeacherStyleId,
});
} catch (error) {
const lyrics = notesForRequestToEngine
Expand Down Expand Up @@ -1320,6 +1342,25 @@ export const singingStore = createPartialStore<SingingStoreTypes>({

logger.info(`Loaded singing voice from cache.`);
} else {
// ピッチ編集を適用したクエリから音量を作る
// 音量値はAPIを叩く毎に変わるので、calc hashしたあとに音量を取得している
const notesForRequestToEngine = createNotesForRequestToEngine(
Comment on lines +1345 to +1347
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ多分本来は合成直前ではなく、ピッチ編集するたびに実行にした方が良さそうなんですよね。
入力が同じボリュームの計算を2回行っちゃってるので。
ただまぁボリュームの計算は重くないので、一旦毎回2回計算しちゃう形で良さそう。

でもなんか忘れそうなのでissue化しておくと安心なのかなとか思いました!

phrase.notes,
tempos,
tpqn,
keyRangeAdjustment,
singingGuide.frameRate,
restDurationSeconds,
);

const volumes = await dispatch("FETCH_SING_FRAME_VOLUME", {
notes: notesForRequestToEngine,
frameAudioQuery: singingGuide.query,
styleId: singingTeacherStyleId,
engineId: singerAndFrameRate.singer.engineId,
});
singingGuide.query.volume = volumes;

const blob = await synthesize(
singerAndFrameRate.singer,
singingGuide.query,
Expand Down Expand Up @@ -2028,6 +2069,35 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
),
},

FETCH_SING_FRAME_VOLUME: {
async action(
{ dispatch },
{
notes,
frameAudioQuery,
engineId,
styleId,
}: {
notes: NoteForRequestToEngine[];
frameAudioQuery: FrameAudioQuery;
engineId: EngineId;
styleId: StyleId;
},
) {
const instance = await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
});
return await instance.invoke("singFrameVolumeSingFrameVolumePost")({
bodySingFrameVolumeSingFrameVolumePost: {
score: {
notes,
},
frameAudioQuery,
},
speaker: styleId,
});
},
},
SET_NOW_AUDIO_EXPORTING: {
mutation(state, { nowAudioExporting }) {
state.nowAudioExporting = nowAudioExporting;
Expand Down
10 changes: 10 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
UserDictWord,
MorphableTargetInfo,
FrameAudioQuery,
Note as NoteForRequestToEngine,
} from "@/openapi";
import {
CharacterInfo,
Expand Down Expand Up @@ -1000,6 +1001,15 @@ export type SingingStoreTypes = {
action(): void;
};

FETCH_SING_FRAME_VOLUME: {
action(palyoad: {
notes: NoteForRequestToEngine[];
frameAudioQuery: FrameAudioQuery;
engineId: EngineId;
styleId: StyleId;
}): Promise<number[]>;
};

TICK_TO_SECOND: {
getter(position: number): number;
};
Expand Down
Loading