Sha256: e1fa7ca225edc406bd312943af1218930001367845adee8d9c638e228f822dc1
Contents?: true
Size: 772 Bytes
Versions: 3
Compression:
Stored size: 772 Bytes
Contents
require "sanitize" module AozoraSsml class Builder def html2ssml(html) doc = ::AozoraSsml::Document.parse(html.encode("utf-8")) ssml_body = create_body_ssml(doc) create_ssml(doc, ssml_body) end def create_body_ssml(doc) Sanitize. fragment(doc.main_text, elements: %w(br ruby rb rp rt div h1 h2 h3 h4 h5)). gsub(%r(<br\s*/?>), '<break />'). gsub(%r(<(?:h\d|div)[^>]*>), '<p>'). gsub(%r(</(?:h\d|div)>), '</p>'). gsub(%r(<rp>[^<]+</rp>), '') end def create_ssml(doc, ssml_body) <<-XML <?xml version="1.0"?> <speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="ja"> <p>#{doc.title}</p> <p>#{doc.author}</p> #{ssml_body} </speak> XML end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aozora-ssml-0.1.2 | lib/aozora-ssml/builder.rb |
aozora-ssml-0.1.1 | lib/aozora-ssml/builder.rb |
aozora-ssml-0.1.0 | lib/aozora-ssml/builder.rb |