(
biz: TaskBiz,
bizId: string,
soundGenerate: SoundGenerateParamType,
result: {},
text: string,
option?: ServerCallOptionType,
)
| 108 | }; |
| 109 | |
| 110 | export const serverSoundGenerate = async ( |
| 111 | biz: TaskBiz, |
| 112 | bizId: string, |
| 113 | soundGenerate: SoundGenerateParamType, |
| 114 | result: {}, |
| 115 | text: string, |
| 116 | option?: ServerCallOptionType, |
| 117 | ): Promise<{ |
| 118 | type: string; |
| 119 | start: number; |
| 120 | end: number; |
| 121 | url: string; |
| 122 | }> => { |
| 123 | text = await replaceSoundGenerateText(text); |
| 124 | option = Object.assign( |
| 125 | { |
| 126 | cache: true, |
| 127 | }, |
| 128 | option, |
| 129 | ) as ServerCallOptionType; |
| 130 | if (option.cache) { |
| 131 | const cacheUrl = await $mapi.file.cacheGetPath({ soundGenerate, text }); |
| 132 | if (cacheUrl) { |
| 133 | return { |
| 134 | type: "success", |
| 135 | start: 0, |
| 136 | end: 0, |
| 137 | url: cacheUrl, |
| 138 | }; |
| 139 | } |
| 140 | } |
| 141 | const server = await serverStore.getByNameVersion( |
| 142 | soundGenerate.serverName, |
| 143 | soundGenerate.serverVersion, |
| 144 | ); |
| 145 | if (!server) { |
| 146 | throw "SoundGenerate server not found: " + soundGenerate.serverName; |
| 147 | } |
| 148 | const serverInfo = await serverStore.serverInfo(server); |
| 149 | let res; |
| 150 | if (soundGenerate.type == "SoundTts") { |
| 151 | res = await serverStore.call(serverInfo, "soundTts", { |
| 152 | id: serverStore.generateTaskId(biz, bizId), |
| 153 | result: result, |
| 154 | param: soundGenerate.ttsParam, |
| 155 | text: text, |
| 156 | }); |
| 157 | } else if (soundGenerate.type == "SoundClone") { |
| 158 | res = await serverStore.call(serverInfo, "soundClone", { |
| 159 | id: serverStore.generateTaskId(biz, bizId), |
| 160 | result: result, |
| 161 | param: soundGenerate.cloneParam, |
| 162 | text: text, |
| 163 | promptAudio: soundGenerate.promptUrl, |
| 164 | promptText: soundGenerate.promptText, |
| 165 | }); |
| 166 | } else { |
| 167 | throw `SoundGenerate.error - type error ${soundGenerate.type}`; |
no test coverage detected