Skip to content

Commit

Permalink
WIP: Implement TTS coefont
Browse files Browse the repository at this point in the history
  • Loading branch information
hakatashi committed Sep 4, 2023
1 parent 50f1677 commit 78ac990
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
36 changes: 36 additions & 0 deletions discord/speeches/coefont.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import axios from 'axios';
import {SynthesizeFunction} from './types';

const authorization = 'Bearer **********';
let prevId: string = null;

const speech: SynthesizeFunction = async (text: string, voiceType: string, {speed, engine}: {speed: number, engine: string}) => {
console.log('start', text);
const res = await axios.post('https://plbwpbyme3.execute-api.ap-northeast-1.amazonaws.com/production/projects/3d03e5ea-4596-43ce-a2c9-35450496d901/parts/e1106b18-03f0-4859-9cf5-e1cdc92a23ca/blocks', JSON.stringify({
coefontId: '19d55439-312d-4a1d-a27b-28f0f31bedc5',
text,
...(prevId ? {prevId} : {}),
}), {
headers: {
authorization,
'content-type': 'application/json',
},
});
console.log(res.data);
const {blockId} = res.data;
prevId = blockId;
const res2 = await axios.get(`https://plbwpbyme3.execute-api.ap-northeast-1.amazonaws.com/production/projects/3d03e5ea-4596-43ce-a2c9-35450496d901/parts/e1106b18-03f0-4859-9cf5-e1cdc92a23ca/blocks/${blockId}/audio`, {
headers: {
authorization,
},
});
console.log(res2.data);
const {location} = res2.data;
const res3 = await axios.get(location, {
responseType: 'arraybuffer',
});
console.log(res3.data);
return {data: res3.data as Buffer};
};

export default speech;
8 changes: 7 additions & 1 deletion discord/speeches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import azure from './azure';
import google from './google';
import voicetext, {Emotion, EmoLV} from './voicetext';
import voicevox from './voicevox';
import coefont from './coefont';

const log = logger.child({bot: 'discord'});

Expand Down Expand Up @@ -45,6 +46,7 @@ enum Voice {
AI = 'AI',
AJ = 'AJ',
AK = 'AK',
AL = 'AL',
}
export {Voice};

Expand All @@ -61,7 +63,7 @@ export const getDefaultVoiceMeta: () => VoiceMeta = () => ({
});

interface Config {
provider: 'google' | 'amazon' | 'azure' | 'voicetext' | 'voicevox',
provider: 'google' | 'amazon' | 'azure' | 'voicetext' | 'voicevox' | 'coefont',
name: string,
emotional?: boolean,
lang?: string,
Expand Down Expand Up @@ -105,6 +107,7 @@ export const speechConfig: Map<Voice, Config> = new Map([
[Voice.AI, {provider: 'google', name: 'ja-JP-Neural2-B', lang: 'ja-JP'}],
[Voice.AJ, {provider: 'google', name: 'ja-JP-Neural2-C', lang: 'ja-JP'}],
[Voice.AK, {provider: 'google', name: 'ja-JP-Neural2-D', lang: 'ja-JP'}],
[Voice.AL, {provider: 'coefont', name: 'Hiroyuki', lang: 'ja-JP'}],
// coming soon
// [Voice., {provider: 'voicevox', name: 'whitecul', emotional: true}],
// [Voice., {provider: 'voicevox', name: 'goki', emotional: true}],
Expand Down Expand Up @@ -133,5 +136,8 @@ export const getSpeech = (text: string, voiceType: Voice, meta: VoiceMeta, audio
if (config.provider === 'voicevox') {
return voicevox(text, config.name, meta);
}
if (config.provider === 'coefont') {
return coefont(text, config.name, meta);
}
return voicetext(text, config.name, meta);
};
4 changes: 3 additions & 1 deletion discord/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class TTS extends EventEmitter {
const tokens = message.content.split(/\s+/);
const user = message.member.user.id;

if (tokens[0]?.toUpperCase() === 'TTS') {
if (tokens[0]?.toUpperCase() === 'TTSDEV') {
if (tokens.length === 1 || tokens[1] === 'start') {
mutex.runExclusive(async () => {
if (!this.users.has(user)) {
Expand Down Expand Up @@ -246,6 +246,8 @@ export default class TTS extends EventEmitter {
providerName = 'VoiceText Web API';
} else if (config.provider === 'voicevox') {
providerName = 'VoiceVox Web API';
} else if (config.provider === 'coefont') {
providerName = 'CoeFont';
} else {
providerName = 'Unknown';
}
Expand Down

0 comments on commit 78ac990

Please sign in to comment.