Text_Spell_Audio
[ class tree: Text_Spell_Audio ] [ index: Text_Spell_Audio ] [ all elements ]

Class: Text_Spell_Audio

Source Location: /Text_Spell_Audio-0.1.0/Text/Spell/Audio.php

Class Overview


Generates an audio wav clips from text


Author(s):

Version:

  • CVS: $Id:$

Copyright:

  • 2006-2007 Tom Harwood

Methods


Inherited Variables

Inherited Methods


Class Details

[line 85]
Generates an audio wav clips from text

Joins up multiple wav file sound clips of letters/numbers being spoken, optionally adding distortion and echo. This could be use to compliment an image-based CAPTCHA to enable people who are unable to read the security image hear it read out instead.

The following example above creates the audio file saying 'a a 1'. The wav files 'a.wav', 'a.wav', '1.wav' are joined together; an appropriate Content-type is echoed to the browser, and the 'a a 1' wav file is output.

  1.  $ac = new Text_Spell_Audio();
  2.  $ac->output('aa1');

This class is supplied with a default directory of sound clips of the characters a-z, 0-9, and #@%&_. Uppercase letters are communicated by adding the prefix 'CAPITAL' (stored in CAPITAL.wav) to the lowercase letters (e.g. B is pronounced 'capital b').

You can specify a path to your own folder of clips:

 /path/to/wavs/a.wav
 /path/to/wavs/b.wav
 ...
 /path/to/wavs/1.wav
 /path/to/wavs/2.wav
 ...
 /path/to/wavs/35.wav ('#', 35 = ASCII #)
 ...
 /path/to/wavs/CAPITAL.wav ('CAPITAL' for forming 'capital X' phrase)

  1.  $ac = new Text_Spell_Audio(array('sound_dir' => '/path/to/wavs/'));
  2.  $ac->output('aa1');

The recordings must all be standard uncompressed (PCM) wav files and must all be either 8bit or 16bit, have the same sample rate, and have the same number of channels.



[ Top ]


Method Detail

__construct (Constructor)   [line 137]

Text_Spell_Audio __construct( [array $options = array()])

Class constructor

Use the Audio_CAPTCHA default sound clips ({pear_data_dir}/Text/Audio/Spell/clips/) by default. The default sound clips contain all characters that the PEAR module Text_Password generates.

  • Access: public

Parameters:

array   $options   —  Options for class. The following indexes are accepted:
  • sound_dir (string) path to wav sound files.
  • distort (integer) distortion level (currently 0 or 1 supported).
  • content_type (string) value for the Content-type HTTP header.
  • capital_format "before" or "after": whether 'CAPITAL' should be said before or after the letter
  • fold_cases (boolean) whether to convert letters to lowercase for file name lookup

[ Top ]

Text_Spell_Audio (Constructor)   [line 109]

Text_Spell_Audio Text_Spell_Audio( [ $options = array()])

Class constructor

PHP4-style constructor


Parameters:

   $options   — 

[ Top ]

getAudio   [line 190]

string getAudio( string $text)

Generates an audio wav file to spell out characters

Example:

  1.  $binWav $ac->getAudio('ab1A');

  • Return: Binary string of new wav file or PEAR_Error on failure
  • Access: public

Parameters:

string   $text   —  character string to spell out

[ Top ]

getFilename   [line 356]

string getFilename( string $char)

Get the expected wav filename containing the sound of a character

The filename is either '[A-Za-z0-9].wav' or, '[ASCII value of char].wav'.

  • Return: Expected filename
  • Access: public

Parameters:

string   $char   —  Single character

[ Top ]

getOptions   [line 172]

array getOptions( )

Returns list of options

[ Top ]

output   [line 332]

boolean output( string $text)

Generates and echoes an audio wav file

This methods outputs an HTTP Content-type header

  • Return: TRUE or PEAR_Error on error
  • Access: public

Parameters:

string   $text   —  character string to spell out

[ Top ]

setOptions   [line 160]

void setOptions( array $options)

Sets options for class

Parameters:

array   $options   —  options list

[ Top ]

_distort   [line 561]

array _distort( array $data, integer $sampleRate, integer $channels)

Distorts the sound file
  • Return: distorted data
  • Access: protected

Parameters:

array   $data   — 
integer   $sampleRate   — 
integer   $channels   — 

[ Top ]

_echo   [line 579]

array _echo( array $data, integer $sampleRate, integer $channels)

Adds echo
  • Return: sound clip with echo
  • Access: protected

Parameters:

array   $data   — 
integer   $sampleRate   — 
integer   $channels   — 

[ Top ]

_isCapital   [line 597]

boolean _isCapital( string $char)

Returns whether a character is to be considered capitalized
  • Return: TRUE is capital, FALSE otherwise
  • Access: protected

Parameters:

string   $char   —  character to check

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:10:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.