program swift; {*************************************** DTSwift AGI Pascal (c) R. Lee Jenkins & DataTrak Business Solutions, Inc. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Lee Jenkins c/o DataTrak Business Solutions, Inc. PO BOX 1035 Oceanview, DE 19970 ****************************************} {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes, SysUtils, process, IniFiles; // constant to hold default parameters if none are specified in the // runtime.conf file.swift const DEFAULT_PARAMS = 'speech/pitch/shift=1,speech/rate=170,audio/sampling-rate=8000,audio/deadair=0'; var Proc: TProcess; sData: string; sVoice: string; sParams: string; sFileVoice: string; sExePath: string; sCmd: string; INI: TIniFile; sSoundFile: string; sRead: string; sl: tstringlist; iPOS: integer; sUnique: string; begin Try // create objects to use // Loop through repeat; begin sRead := ''; ReadLn(INPUT, sRead); if (POS('agi_uniqueid', sRead) > 0) then begin ipos := pos(':', sRead); sUnique := Trim(Copy(sRead, iPOS + 2, 1024)); end; if (length(sread) <= 0) then break; if (sRead = #0) then break; if (sread = '') then break; end; until (Trim(sRead) = ''); // get run parameters from the local .conf file ini := TInifile.Create('runtime.conf'); try sParams := ini.ReadString('runtime', 'params', DEFAULT_PARAMS); sFileVoice := ini.ReadString('runtime', 'voice', ''); sExePath := ini.ReadString('runtime', 'execpath','/opt/swift/bin'); finally; ini.free; end; // populated new filename sSoundFile := sUnique + '.wav'; sData := paramstr(1); sVoice := paramstr(2); try // which voice to use? If none specified use the default if (POS('/', sData) > 0) then begin // assume it's path to a text file. Build Cmd line accordingly. sCmd := sExePath + '/swift -f ' + sData + ' -o /tmp/' + sSoundFile; sCmd := sCmd + ' -p ' + sParams; end else begin // assume that we are synthesizing the actual text provided in parameter to app sCmd := sExePath + '/swift -o /tmp/' + sSoundFile; sCmd := sCmd + ' -p ' + sParams + ' "'+ sData + '"'; end; // Send command and write to file Proc := TProcess.create(nil); Proc.Options := Proc.Options + [poWaitOnExit]; Proc.CommandLine := sCmd; Proc.Execute; WriteLn(OUTPUT, 'EXEC PLAYBACK /tmp/' + sSoundFile + #13#10); ReadLn(INPUT, sCmd); sysutils.ExecuteProcess('rm', ['-f /tmp/'+ sSoundfile]); finally; Proc.free; end; except on e: exception do begin sl := tstringlist.create; if (fileexists('/var/lib/asterisk/agi-bin/debug.txt')) then sl.loadfromfile('/var/lib/asterisk/agi-bin/debug.txt'); sl.Add('error: ' + e.message); sl.SaveToFile('/var/lib/asterisk/agi-bin/debug.txt'); sl.Free; end; end; end.