regarding Audio::wave

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhurathod
    New Member
    • Mar 2008
    • 6

    regarding Audio::wave

    Hi

    I am working telcom domain project where i have to record the voice and playback it.From google i got a code suitable to my project.I did updations added and installed few modules .I installed IO::module for getline function .after installing that am getting as "spiffy constructor 'io'"error ...........and string found where operator expected in io::all...."\.. .\all.pm"
    please guys help to solve this problem
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by madhurathod
    Hi

    I am working telcom domain project where i have to record the voice and playback it.From google i got a code suitable to my project.I did updations added and installed few modules .I installed IO::module for getline function .after installing that am getting as "spiffy constructor 'io'"error ...........and string found where operator expected in io::all...."\.. .\all.pm"
    please guys help to solve this problem
    Can you post your code here and also, please post exactly what was output to the screen or log file?

    Thanks,

    Jeff

    Comment

    • rohitbasu77
      New Member
      • Feb 2008
      • 89

      #3
      post the script... give the error print....

      Comment

      • madhurathod
        New Member
        • Mar 2008
        • 6

        #4
        Hi,
        #
        # $Id: Vgetty.pm,v 1.2 1998/07/11 20:33:19 kas Exp $
        #
        # Copyright (c) 1998 Jan "Yenya" Kasprzak <kas@fi.muni.cz >. All rights
        # reserved. This package is free software; you can redistribute it and/or
        # modify it under the same terms as Perl itself.
        #

        package Modem::Vgetty;

        use FileHandle;
        use POSIX;
        use strict;

        use Carp;

        use vars qw($testing $log_file $VERSION);

        $VERSION='0.01' ;
        $testing = 0;
        $log_file = '/var/log/voicelog';

        my @event_names = qw(BONG_TONE BUSY_TONE CALL_WAITING DIAL_TONE
        DATA_CALLING_TO NE DATA_OR_FAX_DET ECTED FAX_CALLING_TON E
        HANDSET_ON_HOOK LOOP_BREAK LOOP_POLARITY_C HANGE NO_ANSWER
        NO_DIAL_TONE NO_VOICE_ENERGY RING_DETECTED RINGBACK_DETECT ED
        RECEIVED_DTMF SILENCE_DETECTE D SIT_TONE TDD_DETECTED
        VOICE_DETECTED UNKNOWN_EVENT);



        sub new {
        my ($class, $infd, $outfd, $pid) = @_;
        my $self = bless {}, $class;

        $infd ||= $ENV{'VOICE_INP UT'};
        $outfd ||= $ENV{'VOICE_OUT PUT'};
        $pid ||= $ENV{'VOICE_PID '};


        $self->{'IN'} = FileHandle->new_from_fd( $infd, "r" )
        || return;
        $self->{'OUT'} = FileHandle->new_from_fd( $outfd, "w" )
        || return;
        $self->{'IN'}->autoflush;
        $self->{'OUT'}->autoflush;

        $self->{'PIPE_BUF_LEN '} = POSIX::_POSIX_P IPE_BUF ;

        $self->{'PID'} = $pid;
        $self->{'LOG'} = FileHandle->new();

        if ($testing > 0) {
        $self->{'LOG'}->open(">>$log_f ile") || return undef;
        $self->{'LOG'}->autoflush;
        $self->{'LOG'}->print("-----------\n### Pid $$ opening log\n----------\n");
        }
        $self->{'EVENTS'} = { map { $_ => {} } @event_names };

        $self->init();

        return $self;

        }


        # The basic two functions (a low-level interface);
        sub receive {
        my $self = shift;
        my $input;
        while(1) {
        $input = $self->{IN}->getline;
        chomp $input;
        $self->{LOG}->print("receive d: $input\n") if $testing > 0;
        last unless defined $self->{EVENTS}->{$input};
        # Handle the event:
        my $dtmf = '';
        if ($input eq 'RECEIVED_DTMF' ) {
        $dtmf = $self->{IN}->getline;
        chomp $dtmf;
        $self->{LOG}->print("DTMF $dtmf\n") if $testing > 0;
        }
        for (keys %{$self->{EVENTS}->{$input}}) {
        $self->{LOG}->print("Runni ng handler $_ for event $input\n") if $testing > 0;
        &{$self->{EVENTS}->{$input}->{$_}}($self, $input, $dtmf);
        $self->{LOG}->print("Handl er $_ for event $input finished.\n") if $testing > 0;
        }
        }
        $input;
        }

        sub send {
        my $self = shift;
        my $output = shift;
        $self->{OUT}->print("$output \n");
        kill PIPE => $self->{PID};
        $self->{LOG}->print("sent: $output\n") if $testing > 0;
        }

        sub expect {
        my $self = shift;
        $self->{LOG}->print("expecti ng: ", (join '|', @_), "\n");
        my $received = $self->receive || return undef;
        for my $expected (@_) {
        return $received if $received eq $expected;
        }
        return undef;
        }

        sub waitfor {
        my $self = shift;
        my $string = shift;
        while ($self->expect($string ) ne $string) { }
        }

        sub chat {
        my $self = shift;
        my @chatscript = @_;
        my $received = 0;
        for my $cmd (@chatscript) {
        $received = 1 ^ $received;
        next if $cmd eq '';
        if ($received == 1) {
        return undef unless $self->expect($cmd) ;

        } else {
        $self->send($cmd);
        }
        }
        return 1;
        }

        # Initial chat
        sub init {
        my $self = shift;
        # $self->chat ('HELLO SHELL', 'HELLO VOICE PROGRAM', 'READY');
        $self->chat ('HELLO SHELL', 'HELLO VOICE PROGRAM');

        return $self;
        }

        # Setting the voice device
        $dev = undef;
        sub device {
        my $self = shift;
        my $dev = shift;
        $self->{LOG}->print("attempt ing to set device $dev") if $testing;
        $self->chat ('', "DEVICE $dev", 'READY') || return undef;
        $self->{DEVICE}=$de v;
        $self->{LOG}->print("sucessf ully set device $dev") if $testing;
        }

        sub shutdown {
        my $self = shift;
        $self->chat ('', 'GOODBYE', 'GOODBYE SHELL');
        $self->{IN}->close;
        $self->{OUT}->close;
        $self->{LOG}->close if $testing > 0;
        }

        sub DESTROY {
        my $self = shift;
        $self->shutdown;
        }

        sub enable_events {
        my $self = shift;
        $self->chat ('', 'ENABLE EVENTS', 'READY');
        }

        sub disable_events {
        my $self = shift;
        $self->chat ('', 'DISABLE EVENTS', 'READY');
        }

        sub beep {
        my $self = shift;
        my $freq = shift;
        my $len = shift;
        $self->chat ('', "BEEP $freq $len", 'BEEPING');
        }

        sub dial {
        my $self = shift;
        my $num = shift;
        $self->chat ('', "DIAL $num", 'DIALING');
        }

        sub getty {
        my $self = shift;
        $self->chat ('', 'GET TTY') || return undef;
        my $id = $self->receive;
        $self->expect ('READY') || return undef;
        return $id;
        }

        sub autostop {
        my $self = shift;
        my $arg = shift;
        $self->chat ('', "AUTOSTOP $arg", 'READY');
        }

        sub play {
        my $self = shift;
        my $file = shift;
        $self->chat ('', "PLAY $file", 'PLAYING');
        }

        sub record {
        my $self = shift;
        my $file = shift;
        $self->chat ('', "RECORD $file", 'RECORDING');
        }

        sub wait {
        my $self = shift;
        my $sec = shift;
        $self->chat ('', "WAIT $sec", 'WAITING');
        }

        sub stop {
        my $self = shift;
        $self->send ('STOP'); # Nechceme READY.
        }

        sub add_handler {
        my $self = shift;
        my $event = shift;
        my $name = shift;
        my $func = shift;
        if (!defined($self->{EVENTS}->{$event})) {
        $self->{LOG}->print("add_han dler: unknown event $event\n")
        if $testing > 0;
        return undef;
        }
        $self->{EVENTS}->{$event}->{$name} = $func;
        }

        sub del_handler {
        my $self = shift;
        my $event = shift;
        my $name = shift;
        if (!defined($self->{EVENTS}->{$event})) {
        $self->{LOG}->print("del_han dler: unknown event $event\n")
        if $testing > 0;
        return undef;
        }
        if (!defined($self->{EVENTS}->{$event}->{$name})) {
        $self->{LOG}->print("del_han dler: trying to delete nonexistent handler $name\n")
        if $testing > 0;
        } else {
        delete $self->{EVENTS}->{$event}->{$name};
        }
        }

        sub play_and_wait {
        my $self = shift;
        my $file = shift;
        $self->play($file);
        $self->waitfor('READY ');
        }
        1;

        __END__

        =head1 NAME

        Modem::Vgetty - interface to vgetty(8)

        =head1 SYNOPSIS

        use Modem::Vgetty;
        $v = new Modem::Vgetty;

        $string = $v->receive;
        $v->send($string );
        $string = $v->expect($str1 , $str2, ...);
        $v->waitfor($strin g);
        $rv = $v->chat($expect 1, $send1, $expect2, $send2, ...);

        $ttyname = $v->getty;
        $rv = $v->device($dev_ty pe);
        $rv = $v->autostop($bool );

        $rv = $v->beep($freq, $len);
        $rv = $v->dial($number );
        $rv = $v->play($filename );
        $rv = $v->record($filena me);
        $rv = $v->wait($seconds) ;
        $rv = $v->play_and_wait( $filename);
        $v->stop;

        $v->add_handler($e vent, $handler_name, $handler);
        $v->del_handler($e vent, $handler_name);
        $v->enable_event s;
        $v->disable_events ;

        $v->shutdown;

        =head1 DESCRIPTION

        C<Modem::Vgetty > is an encapsulation object for writing applications
        for voice modems using the L<vgetty/8> or L<vm/8> package. The answering
        machines and sofisticated voice applications can be written using this
        module.

        =head1 OVERVIEW

        I<Voice modem> is a special kind of modem, which (besides the normal
        data and/or fax mode) can communicate also in voice mode. It means
        it can record sounds it hears from the phone line to the file,
        Play-back recorded files, it can beep to the line, and it can detect
        various standard sounds coming from the line (busy tone, silence,
        dual tone modulation frequency (DTMF) keypad tones, etc).
        An example of the voice modem can be the ZyXEL U1496, US Robotics
        Sportster (not Courier), etc.

        To use this software with the voice modem you need to have the
        L<vgetty/8> package installed. B<Vgetty> is distributed as a part of
        B<mgetty> package. In fact, B<vgetty> is a L<mgetty/8> with the voice
        extensions. Vgetty has some support for scripting - when it receives
        an incoming call, it runs a voice shell (it is program specified in
        the B<voice.conf> file) as its child process, establishes the read
        and write pipes to it, and tells it the number of the appropriate
        descriptors in the environment variables. Voice shell can now
        communicate with B<vgetty>. It can tell B<vgetty> "Play this file",
        or "Record anything you hear to that file", or "Notify me when
        user hangs up", etc. Sophisticated voice systems and answering
        machines can be build on top of B<vgetty>.

        B<mgetty> (including the B<vgetty>) is available at
        the following URL:

        ftp://ftp.leo.org/pub/comp/os/unix/networking/mgetty/

        Originally there was a (Bourne) shell interface to B<vgetty> only.
        The B<Modem::Vgetty > module allows user to write the voice shell in Perl.
        The typical use is to write a script and point the B<vgetty> to it
        (in B<voice.conf> file). The script will be run when somebody calls in.
        Another use is running voice shell from the L<vm/8> program, which
        can for example dial somewhere and say something.

        =head1 QUICK START

        #!/usr/bin/perl
        use Modem::Vgetty;
        my $v = new Modem::Vgetty;
        $v->add_handler('B USY_TONE', 'endh', sub { $v->stop; exit(0); });
        $v->enable_event s;
        $v->record('/tmp/hello.rmd');
        sleep 20;
        $v->stop;
        $v->shutdown;

        The above example installs the simple `exit now'-style handler for the
        B<BUSY_TONE> event (which is sent by B<vgetty> when user hangs up)
        and then records the B<hello.rmd> file. Put this text into a file
        and then point B<vgetty> to it in the B<voice.conf>. After you dial into
        your voice modem, you can record a 20-seconds of some message.
        Verify that B</tmp/hello.rmd> exists. Now delete the line contaning
        the word "record" and two subsequent lines and insert to the file
        the following line instead of them:

        $v->play_and_wait( '/tmp/hello.rmd');

        Now call the voice modem and listen to the sounds you have just recorded.


        =head1 METHODS

        =head2 Begin and end of communication

        The B<Modem::Vgetty > object will initialize the communication pipes to
        the B<vgetty> at the creation time - in the constructor. The closing
        of the communication is done via the B<shutdown> method:

        $v->shutdown;

        The module will call this method itself from the destructor, if you do
        not call it explicitly.

        =head2 Low-level communication

        Comment

        • madhurathod
          New Member
          • Mar 2008
          • 6

          #5
          Hi rohitbasu77,

          #
          # $Id: Vgetty.pm,v 1.2 1998/07/11 20:33:19 kas Exp $
          #
          # Copyright (c) 1998 Jan "Yenya" Kasprzak <kas@fi.muni.cz >. All rights
          # reserved. This package is free software; you can redistribute it and/or
          # modify it under the same terms as Perl itself.
          #

          package Modem::Vgetty;

          use FileHandle;
          use POSIX;
          use strict;

          use Carp;

          use vars qw($testing $log_file $VERSION);

          $VERSION='0.01' ;
          $testing = 0;
          $log_file = '/var/log/voicelog';

          my @event_names = qw(BONG_TONE BUSY_TONE CALL_WAITING DIAL_TONE
          DATA_CALLING_TO NE DATA_OR_FAX_DET ECTED FAX_CALLING_TON E
          HANDSET_ON_HOOK LOOP_BREAK LOOP_POLARITY_C HANGE NO_ANSWER
          NO_DIAL_TONE NO_VOICE_ENERGY RING_DETECTED RINGBACK_DETECT ED
          RECEIVED_DTMF SILENCE_DETECTE D SIT_TONE TDD_DETECTED
          VOICE_DETECTED UNKNOWN_EVENT);



          sub new {
          my ($class, $infd, $outfd, $pid) = @_;
          my $self = bless {}, $class;

          $infd ||= $ENV{'VOICE_INP UT'};
          $outfd ||= $ENV{'VOICE_OUT PUT'};
          $pid ||= $ENV{'VOICE_PID '};


          $self->{'IN'} = FileHandle->new_from_fd( $infd, "r" )
          || return;
          $self->{'OUT'} = FileHandle->new_from_fd( $outfd, "w" )
          || return;
          $self->{'IN'}->autoflush;
          $self->{'OUT'}->autoflush;

          $self->{'PIPE_BUF_LEN '} = POSIX::_POSIX_P IPE_BUF ;

          $self->{'PID'} = $pid;
          $self->{'LOG'} = FileHandle->new();

          if ($testing > 0) {
          $self->{'LOG'}->open(">>$log_f ile") || return undef;
          $self->{'LOG'}->autoflush;
          $self->{'LOG'}->print("-----------\n### Pid $$ opening log\n----------\n");
          }
          $self->{'EVENTS'} = { map { $_ => {} } @event_names };

          $self->init();

          return $self;

          }


          # The basic two functions (a low-level interface);
          sub receive {
          my $self = shift;
          my $input;
          while(1) {
          $input = $self->{IN}->getline;
          chomp $input;
          $self->{LOG}->print("receive d: $input\n") if $testing > 0;
          last unless defined $self->{EVENTS}->{$input};
          # Handle the event:
          my $dtmf = '';
          if ($input eq 'RECEIVED_DTMF' ) {
          $dtmf = $self->{IN}->getline;
          chomp $dtmf;
          $self->{LOG}->print("DTMF $dtmf\n") if $testing > 0;
          }
          for (keys %{$self->{EVENTS}->{$input}}) {
          $self->{LOG}->print("Runni ng handler $_ for event $input\n") if $testing > 0;
          &{$self->{EVENTS}->{$input}->{$_}}($self, $input, $dtmf);
          $self->{LOG}->print("Handl er $_ for event $input finished.\n") if $testing > 0;
          }
          }
          $input;
          }

          sub send {
          my $self = shift;
          my $output = shift;
          $self->{OUT}->print("$output \n");
          kill PIPE => $self->{PID};
          $self->{LOG}->print("sent: $output\n") if $testing > 0;
          }

          sub expect {
          my $self = shift;
          $self->{LOG}->print("expecti ng: ", (join '|', @_), "\n");
          my $received = $self->receive || return undef;
          for my $expected (@_) {
          return $received if $received eq $expected;
          }
          return undef;
          }

          sub waitfor {
          my $self = shift;
          my $string = shift;
          while ($self->expect($string ) ne $string) { }
          }

          sub chat {
          my $self = shift;
          my @chatscript = @_;
          my $received = 0;
          for my $cmd (@chatscript) {
          $received = 1 ^ $received;
          next if $cmd eq '';
          if ($received == 1) {
          return undef unless $self->expect($cmd) ;

          } else {
          $self->send($cmd);
          }
          }
          return 1;
          }

          # Initial chat
          sub init {
          my $self = shift;
          # $self->chat ('HELLO SHELL', 'HELLO VOICE PROGRAM', 'READY');
          $self->chat ('HELLO SHELL', 'HELLO VOICE PROGRAM');

          return $self;
          }

          # Setting the voice device
          $dev = undef;
          sub device {
          my $self = shift;
          my $dev = shift;
          $self->{LOG}->print("attempt ing to set device $dev") if $testing;
          $self->chat ('', "DEVICE $dev", 'READY') || return undef;
          $self->{DEVICE}=$de v;
          $self->{LOG}->print("sucessf ully set device $dev") if $testing;
          }

          sub shutdown {
          my $self = shift;
          $self->chat ('', 'GOODBYE', 'GOODBYE SHELL');
          $self->{IN}->close;
          $self->{OUT}->close;
          $self->{LOG}->close if $testing > 0;
          }

          sub DESTROY {
          my $self = shift;
          $self->shutdown;
          }

          sub enable_events {
          my $self = shift;
          $self->chat ('', 'ENABLE EVENTS', 'READY');
          }

          sub disable_events {
          my $self = shift;
          $self->chat ('', 'DISABLE EVENTS', 'READY');
          }

          sub beep {
          my $self = shift;
          my $freq = shift;
          my $len = shift;
          $self->chat ('', "BEEP $freq $len", 'BEEPING');
          }

          sub dial {
          my $self = shift;
          my $num = shift;
          $self->chat ('', "DIAL $num", 'DIALING');
          }

          sub getty {
          my $self = shift;
          $self->chat ('', 'GET TTY') || return undef;
          my $id = $self->receive;
          $self->expect ('READY') || return undef;
          return $id;
          }

          sub autostop {
          my $self = shift;
          my $arg = shift;
          $self->chat ('', "AUTOSTOP $arg", 'READY');
          }

          sub play {
          my $self = shift;
          my $file = shift;
          $self->chat ('', "PLAY $file", 'PLAYING');
          }

          sub record {
          my $self = shift;
          my $file = shift;
          $self->chat ('', "RECORD $file", 'RECORDING');
          }

          sub wait {
          my $self = shift;
          my $sec = shift;
          $self->chat ('', "WAIT $sec", 'WAITING');
          }

          sub stop {
          my $self = shift;
          $self->send ('STOP'); # Nechceme READY.
          }

          sub add_handler {
          my $self = shift;
          my $event = shift;
          my $name = shift;
          my $func = shift;
          if (!defined($self->{EVENTS}->{$event})) {
          $self->{LOG}->print("add_han dler: unknown event $event\n")
          if $testing > 0;
          return undef;
          }
          $self->{EVENTS}->{$event}->{$name} = $func;
          }

          sub del_handler {
          my $self = shift;
          my $event = shift;
          my $name = shift;
          if (!defined($self->{EVENTS}->{$event})) {
          $self->{LOG}->print("del_han dler: unknown event $event\n")
          if $testing > 0;
          return undef;
          }
          if (!defined($self->{EVENTS}->{$event}->{$name})) {
          $self->{LOG}->print("del_han dler: trying to delete nonexistent handler $name\n")
          if $testing > 0;
          } else {
          delete $self->{EVENTS}->{$event}->{$name};
          }
          }

          sub play_and_wait {
          my $self = shift;
          my $file = shift;
          $self->play($file);
          $self->waitfor('READY ');
          }
          1;

          __END__

          =head1 NAME

          Modem::Vgetty - interface to vgetty(8)

          =head1 SYNOPSIS

          use Modem::Vgetty;
          $v = new Modem::Vgetty;

          $string = $v->receive;
          $v->send($string );
          $string = $v->expect($str1 , $str2, ...);
          $v->waitfor($strin g);
          $rv = $v->chat($expect 1, $send1, $expect2, $send2, ...);

          $ttyname = $v->getty;
          $rv = $v->device($dev_ty pe);
          $rv = $v->autostop($bool );

          $rv = $v->beep($freq, $len);
          $rv = $v->dial($number );
          $rv = $v->play($filename );
          $rv = $v->record($filena me);
          $rv = $v->wait($seconds) ;
          $rv = $v->play_and_wait( $filename);
          $v->stop;

          $v->add_handler($e vent, $handler_name, $handler);
          $v->del_handler($e vent, $handler_name);
          $v->enable_event s;
          $v->disable_events ;

          $v->shutdown;

          =head1 DESCRIPTION

          C<Modem::Vgetty > is an encapsulation object for writing applications
          for voice modems using the L<vgetty/8> or L<vm/8> package. The answering
          machines and sofisticated voice applications can be written using this
          module.

          =head1 OVERVIEW

          I<Voice modem> is a special kind of modem, which (besides the normal
          data and/or fax mode) can communicate also in voice mode. It means
          it can record sounds it hears from the phone line to the file,
          Play-back recorded files, it can beep to the line, and it can detect
          various standard sounds coming from the line (busy tone, silence,
          dual tone modulation frequency (DTMF) keypad tones, etc).
          An example of the voice modem can be the ZyXEL U1496, US Robotics
          Sportster (not Courier), etc.

          To use this software with the voice modem you need to have the
          L<vgetty/8> package installed. B<Vgetty> is distributed as a part of
          B<mgetty> package. In fact, B<vgetty> is a L<mgetty/8> with the voice
          extensions. Vgetty has some support for scripting - when it receives
          an incoming call, it runs a voice shell (it is program specified in
          the B<voice.conf> file) as its child process, establishes the read
          and write pipes to it, and tells it the number of the appropriate
          descriptors in the environment variables. Voice shell can now
          communicate with B<vgetty>. It can tell B<vgetty> "Play this file",
          or "Record anything you hear to that file", or "Notify me when
          user hangs up", etc. Sophisticated voice systems and answering
          machines can be build on top of B<vgetty>.

          B<mgetty> (including the B<vgetty>) is available at
          the following URL:

          ftp://ftp.leo.org/pub/comp/os/unix/networking/mgetty/

          Originally there was a (Bourne) shell interface to B<vgetty> only.
          The B<Modem::Vgetty > module allows user to write the voice shell in Perl.
          The typical use is to write a script and point the B<vgetty> to it
          (in B<voice.conf> file). The script will be run when somebody calls in.
          Another use is running voice shell from the L<vm/8> program, which
          can for example dial somewhere and say something.

          =head1 QUICK START

          #!/usr/bin/perl
          use Modem::Vgetty;
          my $v = new Modem::Vgetty;
          $v->add_handler('B USY_TONE', 'endh', sub { $v->stop; exit(0); });
          $v->enable_event s;
          $v->record('/tmp/hello.rmd');
          sleep 20;
          $v->stop;
          $v->shutdown;

          The above example installs the simple `exit now'-style handler for the
          B<BUSY_TONE> event (which is sent by B<vgetty> when user hangs up)
          and then records the B<hello.rmd> file. Put this text into a file
          and then point B<vgetty> to it in the B<voice.conf>. After you dial into
          your voice modem, you can record a 20-seconds of some message.
          Verify that B</tmp/hello.rmd> exists. Now delete the line contaning
          the word "record" and two subsequent lines and insert to the file
          the following line instead of them:

          $v->play_and_wait( '/tmp/hello.rmd');

          Now call the voice modem and listen to the sounds you have just recorded.


          =head1 METHODS

          =head2 Begin and end of communication

          The B<Modem::Vgetty > object will initialize the communication pipes to
          the B<vgetty> at the creation time - in the constructor. The closing
          of the communication is done via the B<shutdown> method:

          $v->shutdown;

          The module will call this method itself from the destructor, if you do
          not call it explicitly.

          =head2 Low-level communication

          Comment

          Working...