Skip to content

Instantly share code, notes, and snippets.

@FromAtom
Last active December 16, 2015 15:09
Show Gist options
  • Save FromAtom/5453390 to your computer and use it in GitHub Desktop.
Save FromAtom/5453390 to your computer and use it in GitHub Desktop.
コマンドライン引数で取得した文章をruby-mecabを使って発音を解析、最後にSayKanaコマンドに読ませる。
# -*- 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}`
}
@asonas
Copy link

asonas commented Apr 24, 2013

シングルクオートとダブルクォートを揃えられるといいですね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment