# RubySpeech RubySpeech is a library for constructing and parsing Text to Speech (TTS) and Automatic Speech Recognition (ASR) documents such as [SSML](http://www.w3.org/TR/speech-synthesis) and [GRXML](http://www.w3.org/TR/speech-grammar/). The primary use case is for construction of these documents to be processed by TTS and ASR engines. ## Installation gem install ruby_speech ## Library RubySpeech provides a DSL for constructing SSML documents like so: ```ruby require 'ruby_speech' speak = RubySpeech::SSML.draw do voice gender: :male, name: 'fred' do string "Hi, I'm Fred. The time is currently " say_as interpret_as: 'date', format: 'dmy' do "01/02/1960" end end end speak.to_s ``` becomes: ```xml Hi, I'm Fred. The time is currently 01/02/1960 ``` Once your `Speak` is fully prepared and you're ready to send it off for processing, you must call `to_doc` on it to add the XML header: ```xml Hi, I'm Fred. The time is currently 01/02/1960 ``` You may also then need to call `to_s`. Construct a GRXML (SRGS) document like this: ```ruby require 'ruby_speech' grammy = RubySpeech::GRXML.draw mode: :dtmf, root: 'pin' do rule id: 'digit' do one_of do ('0'..'9').map { |d| item { d } } end end rule id: 'pin', scope: 'public' do one_of do item do item repeat: '4' do ruleref uri: '#digit' end "#" end item do "* 9" end end end end grammy.to_s ``` which becomes ```xml 0 1 2 3 4 5 6 7 8 9 # * 9 ``` ### Grammar matching It is possible to match some arbitrary input against a GRXML grammar. In order to do so, certain normalization routines should first be run on the grammar in order to prepare it for matching. These are reference inlining, tokenization and whitespace normalization, and are described [in the SRGS spec](http://www.w3.org/TR/speech-grammar/#S2.1). This process will transform the above grammar like so: ```ruby grammy.inline! grammy.tokenize! grammy.normalize_whitespace ``` ```xml 0 1 2 3 4 5 6 7 8 9 # * 9 ``` Matching against some sample input strings then returns the following results: ```ruby >> subject.match '*9' => # >> subject.match '1234#' => # >> subject.match '5678#' => # >> subject.match '1111#' => # >> subject.match '111' => # ``` Check out the [YARD documentation](http://rdoc.info/github/benlangfeld/ruby_speech/master/frames) for more ## Features: ### SSML * Document construction * `` * `` * `` * `` * `` * `