Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
0918nobita committed Mar 4, 2024
1 parent 00f7bb3 commit 182795a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
*.mp3
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ $ npm run lint
```bash
$ npm run format
```

```bash
$ curl -H "Content-Type: application/json; charset=utf-8" \
-d @synthesize-input.json \
https://texttospeech.googleapis.com/v1beta1/text:synthesize?key={YOUR_API_KEY} | \
jq -r '.audioContent' | base64 --decode > output.mp3
```
16 changes: 16 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type Lang = 'en-US' | 'ja-JP';

const translation = {
alwaysDisplayPinyin: {
'en-US': 'Always display pinyin',
'ja-JP': 'ピンインを常に表示する',
},
language: {
'en-US': 'Language',
'ja-JP': '言語',
},
} as const satisfies Record<string, Record<Lang, string>>;

export function t(lang: Lang, key: keyof typeof translation): string {
return translation[key][lang];
}
21 changes: 20 additions & 1 deletion src/setting-tab-impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Obsidian from 'obsidian';

import { type Lang, t } from './i18n';
import type { SettingTab } from './setting-tab';
import type { Plugin } from './plugin';

Expand All @@ -20,7 +21,25 @@ export class SettingTabImpl
containerEl.empty();

new Obsidian.Setting(containerEl)
.setName('Always display pinyin')
.setName(t(this.plugin.settings.lang, 'language'))
.addDropdown((dropdown) => {
const options = {
'en-US': 'English',
'ja-JP': '日本語',
} as const satisfies Record<Lang, string>;

dropdown
.addOptions(options)
.setValue(this.plugin.settings.lang)
.onChange(async (value) => {
this.plugin.settings.lang = value as Lang;
await this.plugin.saveSettings();
this.display();
});
});

new Obsidian.Setting(containerEl)
.setName(t(this.plugin.settings.lang, 'alwaysDisplayPinyin'))
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.alwaysDisplayPinyin)
Expand Down
4 changes: 4 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { Lang } from './i18n';

export interface Settings {
alwaysDisplayPinyin: boolean;
lang: Lang;
}

export const defaultSettings: Settings = {
alwaysDisplayPinyin: false,
lang: 'en-US',
};
12 changes: 12 additions & 0 deletions synthesize-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"audioConfig": {
"audioEncoding": "MP3"
},
"input": {
"text": "我正在做作业。"
},
"voice": {
"languageCode": "cmn-CN",
"name": "cmn-CN-Wavenet-A"
}
}

0 comments on commit 182795a

Please sign in to comment.