|
function getClientInfo() { |
|
return { |
|
"name": SV.T("Pronounce Hiragana with Chinese Voice"), |
|
"author": "SO_C", |
|
"versionNumber": 1.2, |
|
"minEditorVersion": 65537 |
|
}; |
|
} |
|
|
|
function getTranslations(langCode) { |
|
if (langCode == "ja-jp") { |
|
return [ |
|
["Pronounce Hiragana with Chinese Voice", "中国語ボイスでひらがなを発音する"], |
|
["Conversion error", "変換エラー"], |
|
[" is not converted.", " を変換できませんでした。"] |
|
]; |
|
} |
|
return []; |
|
} |
|
|
|
function main() { |
|
var selection = SV.getMainEditor().getSelection(); |
|
var selectedNotes = selection.getSelectedNotes(); |
|
|
|
for (var i = 0; i < selectedNotes.length; i++) { |
|
var note = selectedNotes[i]; |
|
var hiragana = note.getLyrics(); |
|
|
|
note.setPhonemes(hiragana2ChinesePronounce(hiragana)); |
|
|
|
} |
|
|
|
SV.finish(); |
|
} |
|
|
|
// hiragana: 日本語ひらがな文字列 |
|
// returns: |
|
// スペース区切りの中国語音素文字列 |
|
// |
|
// references: https://twitter.com/shizumu96/status/1362542581645672453 |
|
// |
|
function hiragana2ChinesePronounce(hiragana) { |
|
var hiragana_array = hiragana.split(""); |
|
var chinese_pronounce = new Array(); |
|
|
|
for (var i = 0; i < hiragana_array.length; i++) { |
|
var hiragana = hiragana_array[i]; |
|
switch (hiragana) { |
|
// あ行 |
|
case "あ": |
|
chinese_pronounce.push("a"); |
|
break; |
|
case "い": |
|
chinese_pronounce.push("i"); |
|
break; |
|
case "う": |
|
switch (hiragana_array[i + 1]) { |
|
case "ぉ": |
|
chinese_pronounce.push("w o"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("i\\"); |
|
break; |
|
} |
|
break; |
|
case "え": |
|
chinese_pronounce.push("e"); |
|
break; |
|
case "お": |
|
chinese_pronounce.push("uo"); |
|
break; |
|
// か行 |
|
case "か": |
|
chinese_pronounce.push("kh a"); |
|
break; |
|
case "き": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("kh j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("kh j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("kh j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("kh i"); |
|
break; |
|
} |
|
break; |
|
case "く": |
|
chinese_pronounce.push("kh i\\"); |
|
break; |
|
case "け": |
|
chinese_pronounce.push("kh e"); |
|
break; |
|
case "こ": |
|
chinese_pronounce.push("kh uo"); |
|
break; |
|
// さ行 |
|
case "さ": |
|
chinese_pronounce.push("s a"); |
|
break; |
|
case "し": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("s` a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("s` i\\"); |
|
i++; |
|
break; |
|
case "ぇ": |
|
chinese_pronounce.push("s` e"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("s` uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("s i"); |
|
break; |
|
} |
|
break; |
|
case "す": |
|
chinese_pronounce.push("s i\\"); |
|
break; |
|
case "せ": |
|
chinese_pronounce.push("s e"); |
|
break; |
|
case "そ": |
|
chinese_pronounce.push("s uo"); |
|
break; |
|
// た行 |
|
case "た": |
|
chinese_pronounce.push("th a"); |
|
break; |
|
case "ち": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("ts`h a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("ts`h i\\"); |
|
i++; |
|
break; |
|
case "ぇ": |
|
chinese_pronounce.push("ts`h e"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("ts`h uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("ts`h i"); |
|
break; |
|
} |
|
break; |
|
case "つ": |
|
chinese_pronounce.push("tsh i\\"); |
|
break; |
|
case "て": |
|
switch (hiragana_array[i + 1]) { |
|
case "ぃ": |
|
chinese_pronounce.push("th i"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("th e"); |
|
break; |
|
} |
|
break; |
|
case "と": |
|
chinese_pronounce.push("th uo"); |
|
break; |
|
// な行 |
|
case "な": |
|
chinese_pronounce.push("n a"); |
|
break; |
|
case "に": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("n j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("n j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("n j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("n i"); |
|
break; |
|
} |
|
break; |
|
case "ぬ": |
|
chinese_pronounce.push("n i\\"); |
|
break; |
|
case "ね": |
|
chinese_pronounce.push("n e"); |
|
break; |
|
case "の": |
|
chinese_pronounce.push("n uo"); |
|
break; |
|
// は行 |
|
case "は": |
|
chinese_pronounce.push("x a"); |
|
break; |
|
case "ひ": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("x j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("x j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("x j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("x i"); |
|
break; |
|
} |
|
break; |
|
case "ふ": |
|
switch (hiragana_array[i + 1]) { |
|
case "ぁ": |
|
chinese_pronounce.push("f a"); |
|
i++; |
|
break; |
|
case "ぃ": |
|
chinese_pronounce.push("f i"); |
|
i++; |
|
break; |
|
case "ぇ": |
|
chinese_pronounce.push("f e"); |
|
i++; |
|
break; |
|
case "ぉ": |
|
chinese_pronounce.push("f o"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("x i\\"); |
|
break; |
|
} |
|
break; |
|
case "へ": |
|
chinese_pronounce.push("x e"); |
|
break; |
|
case "ほ": |
|
chinese_pronounce.push("x uo"); |
|
break; |
|
// ま行 |
|
case "ま": |
|
chinese_pronounce.push("m a"); |
|
break; |
|
case "み": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("m j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("m j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("m j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("m i"); |
|
break; |
|
} |
|
break; |
|
case "む": |
|
chinese_pronounce.push("m i\\"); |
|
break; |
|
case "め": |
|
chinese_pronounce.push("m e"); |
|
break; |
|
case "も": |
|
chinese_pronounce.push("m uo"); |
|
break; |
|
// や行 |
|
case "や": |
|
chinese_pronounce.push("j ia"); |
|
break; |
|
case "ゆ": |
|
chinese_pronounce.push("j i\\"); |
|
break; |
|
case "よ": |
|
chinese_pronounce.push("j uo"); |
|
break; |
|
|
|
// ら行 |
|
case "ら": |
|
chinese_pronounce.push("l a"); |
|
break; |
|
case "り": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("l j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("l j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("l j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("l i"); |
|
break; |
|
} |
|
break; |
|
case "る": |
|
chinese_pronounce.push("l i\\"); |
|
break; |
|
case "れ": |
|
chinese_pronounce.push("l e"); |
|
break; |
|
case "ろ": |
|
chinese_pronounce.push("l uo"); |
|
break; |
|
|
|
// わ行 |
|
case "わ": |
|
chinese_pronounce.push("w a"); |
|
break; |
|
case "を": |
|
chinese_pronounce.push("o"); |
|
break; |
|
case "ん": |
|
chinese_pronounce.push(":n"); |
|
break; |
|
|
|
// 濁音 |
|
// が行 |
|
case "が": |
|
switch (hiragana_array[i + 1]) { |
|
case "鼻": |
|
chinese_pronounce.push("N a"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("k a"); |
|
break; |
|
} |
|
break; |
|
case "ぎ": |
|
switch (hiragana_array[i + 1]) { |
|
case "鼻": |
|
chinese_pronounce.push("N i"); |
|
i++; |
|
break; |
|
case "ゃ": |
|
chinese_pronounce.push("k j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("k j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("k j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("k i"); |
|
break; |
|
} |
|
break; |
|
case "ぐ": |
|
switch (hiragana_array[i + 1]) { |
|
case "鼻": |
|
chinese_pronounce.push("N i\\"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("k i\\"); |
|
break; |
|
} |
|
break; |
|
case "げ": |
|
switch (hiragana_array[i + 1]) { |
|
case "鼻": |
|
chinese_pronounce.push("N e"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("k e"); |
|
break; |
|
} |
|
break; |
|
case "ご": |
|
switch (hiragana_array[i + 1]) { |
|
case "鼻": |
|
chinese_pronounce.push("N uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("k uo"); |
|
break; |
|
} |
|
break; |
|
// ざ行 |
|
case "ざ": |
|
chinese_pronounce.push("ts a"); |
|
break; |
|
case "じ": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("ts\\ a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("ts\\ i\\"); |
|
i++; |
|
break; |
|
case "ぇ": |
|
chinese_pronounce.push("ts\\ e"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("ts\\ uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("ts i"); |
|
break; |
|
} |
|
break; |
|
case "ず": |
|
chinese_pronounce.push("ts i\\"); |
|
break; |
|
case "ぜ": |
|
chinese_pronounce.push("ts e"); |
|
break; |
|
case "ぞ": |
|
chinese_pronounce.push("ts uo"); |
|
break; |
|
// だ行 |
|
case "だ": |
|
chinese_pronounce.push("t a"); |
|
break; |
|
case "ぢ": // FIXME:「じ」のコピペ |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("ts\\ a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("ts\\ i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("ts\\ uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("ts i"); |
|
break; |
|
} |
|
break; |
|
case "づ": // 「ず」と同じ |
|
chinese_pronounce.push("ts i\\"); |
|
break; |
|
case "で": |
|
switch (hiragana_array[i + 1]) { |
|
case "ぃ": |
|
chinese_pronounce.push("t i"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("t e"); |
|
break; |
|
} |
|
break; |
|
case "ど": |
|
chinese_pronounce.push("t uo"); |
|
break; |
|
// ば行 |
|
case "ば": |
|
chinese_pronounce.push("p a"); |
|
break; |
|
case "び": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("p j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("p j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("p j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("p i"); |
|
break; |
|
} |
|
break; |
|
case "ぶ": |
|
chinese_pronounce.push("p i\\"); |
|
break; |
|
case "べ": |
|
chinese_pronounce.push("p e"); |
|
break; |
|
case "ぼ": |
|
chinese_pronounce.push("p uo"); |
|
break; |
|
|
|
// 半濁音 |
|
// ぱ行 |
|
case "ぱ": |
|
chinese_pronounce.push("ph a"); |
|
break; |
|
case "ぴ": |
|
switch (hiragana_array[i + 1]) { |
|
case "ゃ": |
|
chinese_pronounce.push("ph j a"); |
|
i++; |
|
break; |
|
case "ゅ": |
|
chinese_pronounce.push("ph j i\\"); |
|
i++; |
|
break; |
|
case "ょ": |
|
chinese_pronounce.push("ph j uo"); |
|
i++; |
|
break; |
|
default: |
|
chinese_pronounce.push("ph i"); |
|
break; |
|
} |
|
break; |
|
case "ぷ": |
|
chinese_pronounce.push("ph i\\"); |
|
break; |
|
case "ぺ": |
|
chinese_pronounce.push("ph e"); |
|
break; |
|
case "ぽ": |
|
chinese_pronounce.push("ph uo"); |
|
break; |
|
|
|
// 促音 |
|
case "っ": |
|
chinese_pronounce.push("cl"); |
|
break; |
|
|
|
default: |
|
SV.showMessageBoxAsync(SV.T("Conversion error"), hiragana + SV.T(" is not converted.")); |
|
break; |
|
} |
|
} |
|
|
|
return chinese_pronounce.join(" "); |
|
} |
Ver 1.1:@shizumu96 さんからいただいた拡張を反映