Last active
December 16, 2015 15:09
-
-
Save FromAtom/5453390 to your computer and use it in GitHub Desktop.
コマンドライン引数で取得した文章をruby-mecabを使って発音を解析、最後にSayKanaコマンドに読ませる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'MeCab' | |
mecab = MeCab::Tagger.new("") | |
ARGV.each{ |arg| | |
kana = '' | |
parse_node = mecab.parseToNode(arg) | |
#要素の中から発音要素だけを取り出す | |
while parse_node | |
feature = parse_node.feature.force_encoding('UTF-8') | |
w = feature.split(',')[8] | |
kana += w if w != nil | |
parse_node = parse_node.next | |
end | |
kana.gsub!("*", "") | |
puts '読み:' + kana | |
`SayKana #{kana}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
22行目で
SayKana #{kana}
変数展開しているなら20行目でもputs "読み: #{kana}"
でもよさそう