Archives for: January 2010
Introduction to write C extension for Ruby
January 16th, 2010Today, I am trying to use festival c/c++ api to say a word. After checking document, I decided to write an extension for ruby.
It is a simple task. All your need to do is:
Write a extension c file.
This file must define a function:
void Init_your_module_name()
It will be called on ruby loading it.
require "your_module_name"
In this function, generally, you must have following codes:
VALUE rb_mFestivalTTS;
rb_mFestivalTTS = rb_define_module( "FestivalTTS" ); //Define a module.
rb_define_module_function( rb_mFestivalTTS, "say", say, 1 ); //Define a function in module.
Write a extconf.rb
# extconf.rb
require 'mkmf'
dir_config('your_package_name')
create_makefile('your_package_name')
You can use find_library and find_header to add library and include path.
Run "make" command.
ruby extconf.rb
make
But it is a complex task too.
mkmf.rb doesn't support C
You must stick to C language.
You must be familiar with Ruby internal
All value passed bewteen extension and ruby inteperator is VALUE. It has a lot of api to manipuate VALUE. You must study <ruby.h>
Especially, you can use VALUE as a string by: StringValueCStr().
ruby脚本判断os
January 14th, 2010ruby定义了一个预定义的常量 RUBY_PLATFORM 可以用来实现平台判断.
在ubuntu 9.10下是 i386-linux
在windows下是i386-mswin32
festivaltts4r分析
January 14th, 2010festivaltts4r是ruby的一个gem,用来实现tts.分析它的代码,发现这是一个非常低效的实现,就是直接执行festival --tts的命令来发声.
festival本身提供festival-client模式和api模式,采用这两种应该可以提供更高效的实现.
Using TTS in Ubuntu
January 14th, 2010Ubuntu uses festival as its TTS solution.
sudo aptitude install festival
But it has problem to work with PluseAudio and Bluetooth. For overcoming this problem, I found following wiki. Please notice following section "Configuration for ESD or PulseAudio"
- Open the configuration file by typing gksudo gedit /etc/festival.scm or gedit ~/.festivalrc in a terminal.
- Add the following lines at the end of the file:
(Parameter.set 'Audio_Method 'esdaudio) - Save the file.
Run jar file in command
January 13th, 2010java -jar file_name_of_jar