Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert english phrases into phonetic japanese kana approximations; also known as Englishru.

License

NotificationsYou must be signed in to change notification settings

Luigi-Pizzolito/English2KanaTransliteration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference

Convert English phrases into phonetic Japanese kana approximations; also known as Englishru. Does not translate English into Japanese, but translates English words into their approximate pronounciations in Japanese.

Based on the English to Katakana transcription code written in Python byYoko Harada (@yokolet) Please see that repo for details on the phonetic conversion.

English to phoneme conversion based onCMUDict. Kanji to Katakana convertion based onKANJIDIC2. Thanks toJMDict andkana. Please refer to those licenses for non-free implementations.

It is a port in Golang with some additional functions:

  • Filtering functions to split, parse, and rejoin sentences which contain punctuation or improper contractions.
  • Alsoaccepts Japanese input; converts any Kanji characters into their most common Hiragana pronounciation, converts Hiragana into Katakana, leaves Katakana as is.
  • Alsoaccepts Romaji input.
  • strict input cleaning mode for use with TTS input that does not understand punctuation and other chars. See header below.

Usage Example

Below is an example go file to test this module. It reads input fromstdin, converts the English sentences into their Japanese transliteration and prints them tostdout.

package mainimport ("github.com/Luigi-Pizzolito/English2KanaTransliteration""bufio""fmt""os")funcmain() {// Create an instance of AllToKanaallToKana:=kanatrans.NewAllToKana()// Listen to stdin indefinitelyreader:=bufio.NewReader(os.Stdin)for {line,err:=reader.ReadString('\n')iferr!=nil {break// Exit loop on error}// Call convertString function with the accumulated lineresult:=allToKana.Convert(line)// Output the resultfmt.Print(result+"\n")}}

Sample Output:

❯ go run .Hello there.ヘロー ゼアー。With this program, you can make Japanese text to speech speak in English!ウィズ ジス プローラ、 ユー キャン メイク ジャーンイーズ テックスト ツー スピーチ スピーク イン イングシュ!watashi wa miku desu~ワタシ ワ ミク デス〜Hello! こんにちは~ ヘロー, miki松原。ヘロー! コンニチハ〜 ヘロー、 ミキショウゲン。

Using individual modules

All2Katakana

// Create an instance of AllToKanaallToKana:=kanatrans.NewAllToKana()// Usagekana:=allToKana.Convert("Hello! watashiwa 初音ミク.")// -> ヘロー! ワタシワ ショオンミク。

Eng2Katakana

// Create an instance of EngToKanaengToKana:=kanatrans.NewEngToKana()// Usagekana:=engToKana.TranscriptSentence("Hello World!")// -> ヘローワールド

Kanji2Katakana

// Create an instance of KanjiToKanakanjiToKana:=kanatrans.NewKanjiToKana()// Usagekana:=kanjiToKana.Convert("初音")// -> ショオン

This needs some work, it just takes the most common pronouciation of each Kanji instead of the correct one for the context. Pull requests are welcome!

Hiragana2Katakana

// Create an instance of HiraganaToKanahiraganaToKana:=kanatrans.NewHiraganaToKana()// Usagekana:=hiraganaToKana.Convert("こんにちは")// -> コンニチハ

Romaji2Katakana

// Create an instance of RomajiToKanaromajiToKana:=kanatrans.NewRomajiToKana()// Usagekana:=romajiToKana.Convert("kita kita desu")// -> キタ キタ デス

ConvertPunctuation

// UsagejapanesePunctuation:=kanatrans.ConvertToJapanesePunctuation("Hello, World!")// -> Hello、 World!

Note for using with Japanese-only text-to-speech (TTS)

This module is intended to allow TTS which only support Japanese to speak english (such as AquesTalk, Softalk, etc). These TTS usually have some limitations in what punctuation may be present in the input; with only commas and stops being interpreted as a pause and all other punctuation causing an error.

To use this module for such TTS input, you may enablestrict input cleaning mode (only Japanese comma and stop on output) by passing a bool in the initialiser forEngToKana,RomajiToKana andAllToKana classes:

// Create an instance of AllToKana with strict punctuation outputallToKana:=kanatrans.NewAllToKana(true)
// Create an instance of EngToKana with strict punctuation outputengToKana:=kanatrans.NewEngToKana(true)
// Create an instance of RomajiToKana with strict punctuation outputromajiToKana:=kanatrans.NewRomajiToKana(true)

You may also use the functionkanatrans.ConvertToJapanesePunctuationRestricted instead ofkanatrans.ConvertToJapanesePunctuation.

Custom callbacks to proccess Kanji, Kana, English & Punctuation

Internally, theAllToKana proccess function uses aKanjiSplitter class to callfunc(string) string functions which handle Kanji, Kana, English and Punctuation respectively:

// Create an instance of KanjiSplitter with proccesing callbackskanjiSplitter:=kanatrans.NewKanjiSplitter(kanjiToKana.Convert,// Kanji callbackhiraganaToKana.Convert,// Gana & Kana callbackengToKana.TranscriptSentence,// English callbackConvertToJapanesePunctuation,// Punctuation callback)

If required, you may use aKanjiSplitter with custom callback functions to provide different processing.

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp