[Freeswitch-users] Unicast isn't working

David Knell dave at 3c.co.uk
Tue May 26 08:08:55 PDT 2009


Hi Artem,

Please to see that some of the stuff I wrote is useful to someone..!

I've written an FS module which will send the audio over - it's more efficient than using unicast.  Let me know if you'd like a copy.

Cheers --

Dave
  ----- Original Message ----- 
  From: ????? ???????? 
  To: freeswitch-users at lists.freeswitch.org 
  Sent: Tuesday, May 26, 2009 9:27 AM
  Subject: [Freeswitch-users] Unicast isn't working


  Hi,

  I am trying to setup ASR in FreeSwitch using Nuance ASR server and MRCP. Both FreeSwitch and Nuance installed on Windows Server 2003. FreeSwitch version is 1.0.3 (12567M)

  I found an example in Perl at http://www.softivr.com/wiki/index.php/FreeSWITCH_MRCP_in_Perl and decided to do the same in C#.
  It establishes connection with Nuance and loads the grammar, everything works fine. The next step is to capture audio from FS and tramsmit it to ASR. This can be done with unicast. We must create an outbound socket and issue "unicast" command. Here it goes:

  private void SetupAudioTransmission()
  {
   EventSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
   EventSocket.SendTimeout = Config.Timeout;
   int ESPort = SearchESPort(EventSocket);

   Thread thrESListener = new Thread(new ThreadStart(ListenerThreadStart));
   thrESListener.Start();
   
   WriteLog(LogLevel.Info, "Creating outbound event socket");
   Session.Execute("socket", "127.0.0.1:" + ESPort); //main thread stops, listener thread listens for outbound socket connection.
   WriteLog(LogLevel.Info, "Outbound event socket disconnected");

   EventSocket.Close();
  }
    
  //here we accept outbound socket and transmit unicast command through it
  private void ListenerThreadStart()
  {
   Socket sockHandler = EventSocket.Accept();
   WriteLog(LogLevel.Info, "Incoming connection");
   sockHandler.Send(MessageEncoding.GetBytes("Connect\n\n"));
     
   WriteLog(LogLevel.Info, GetServerResponse(sockHandler));

   int rtpPort = (RTPSocket.RemoteEndPoint as IPEndPoint).Port;
   string command = string.Format("sendmsg\r\ncall-command: unicast\r\nlocal-ip: {0}\r\nlocal-port: {1}\r\nremote-ip: {2}\r\n" +
    "remote-port: {3}\r\ntransport: udp\r\nflags: native\r\n\r\n", Config.LocalIP, rtpPort + 1, Config.LocalIP, rtpPort);

   WriteLog(LogLevel.Info, command);

   sockHandler.Send(MessageEncoding.GetBytes(command));
   WriteLog(LogLevel.Info, GetServerResponse(sockHandler));
   
   sockHandler.Disconnect(false);  
   sockHandler.Close();  
  }

  After this, FS writes that unicast has been created on corresponding IPs and ports. It really creates an UDP socket, but doesn't transmit any data through it. I tested it with Wireshark and from my application, nothing was detected.
  Also, if we specify "transport:tcp" in unicast command, it uses UDP anyway, that's strange.

  Here is how I listen UDP packets.
  private void DetectSpeech()
  {
   WriteLog(LogLevel.Info, "Reading audio");
   byte[] FSRecvBuf = new byte[2048];
   
   IPEndPoint epFS = new IPEndPoint(IPAddress.Loopback, (RTPSocket.RemoteEndPoint as IPEndPoint).Port);
   FSSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
   FSSocket.ReceiveTimeout = 100000;
   FSSocket.SendTimeout = 100000;
   WriteLog(LogLevel.Info, "Binding socket to " + epFS.Port);

   FSSocket.Bind(epFS);
   FSSocket.Connect(new IPEndPoint(IPAddress.Loopback, epFS.Port + 1));
     
   while (Session.Ready())
   {
    int recvCount = FSSocket.Receive(FSRecvBuf);
    WriteLog(LogLevel.Info, "Received bytes: " + recvCount);
   }
  }

  Can someone help me to solve this? Do I do something wrong or I forgot something or it doesn't work at all?

  Best regards.
  Artem




------------------------------------------------------------------------------


  _______________________________________________
  Freeswitch-users mailing list
  Freeswitch-users at lists.freeswitch.org
  http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
  UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
  http://www.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20090526/2094b41b/attachment-0002.html 


More information about the FreeSWITCH-users mailing list