Stream Speech Data to Phone - Actively Refused

Version 1
    This document was generated from CDN thread

    Created by: kirk moren on 28-01-2010 03:52:13 PM
    I have a service that basically connects to a data source to get text and display it on the phone and then a soft key will allow the user to hear that text via a subsequent G.711 audio stream.   The hear softkey feature, which is written in c# (3.5 fx) uses the .net speechsynhesizer to create a stream of data that is g.711 ulaw compliant (8000 samples / second, 8 bits / sample, 1 channel, 20 bytes / second, block align 2) ...

    // convert text to audio stream using .net 3.x speechsynthesis g.711 u-law (pcm 64kb/s bit rate (u-law encodes 14-bit to 8-bit samples by adding 32 / binary 100000)
    speaker = 
    new SpeechSynthesizer();
    // can also change voice with SelectVoice method
    speaker.Rate = 1;
     // encoding format enums are Pcm, ALaw, ULaw
    int  samplesPerSecond = 8000; 
    int bitsPerSample = 8;
    // System.Speech.AudioFormat.AudioBitsPerSample.Eight
    int channelCount = 1;
    // System.Speech.AudioFormat.AudioChannel.Mono
    int  averageBytesPerSecond = 20;<font size="2">
     int  blockAlign = 2;<font size="2">
    byte[] formatSpecificData = null;<font size="2">
    streamDestination = new MemoryStream();
    new SpeechAudioFormatInfo(EncodingFormat.ULaw, samplesPerSecond, bitsPerSample, channelCount, averageBytesPerSecond, blockAlign, formatSpecificData));
    ... after the generic stream is created, the server sends a RTPRx to the phone to listen to the server on port 31250 and then creates a streaming socket, wraps that socket in a network stream and then writes the stream.  The streaming is asynchronous but that's not really relevant to the problem at hand...
    serverIP = Request.ServerVariables["LOCAL_ADDR"];<font size="2">
    string phoneIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];<font size="2">
    int  targetPort = 31250;

    string strPush = "<CiscoIPPhoneExecute><ExecuteItem URL=\"RTPRx:" + serverIP + ":" + targetPort + ":75\"/></CiscoIPPhoneExecute>"; // server:port:volume(0-100)

    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    socket.Connect(new IPEndPoint(IPAddress.Parse(phoneIP), targetPort)); // <-- errors here<font size="2">
    socket.Blocking = true;

    // create networkstream to stream over socket the audio stream
    nstream = new NetworkStream(socket, false); // true closes socket when network stream closes
    return nstream.BeginWrite(streamDestination.GetBuffer(), 0, (int)streamDestination.Length, null, null); // async call to stream in case larges amounts of data (close stream and clean up in endinvoke method as well as send RTPRx:Stop)

    An error occurs prior to the streaming when the web server ( is trying to perform the Connect operation with an error of "No connection could be made because the target machine actively refused it".    I thought that as a function of the RTPRx being sent to the phone that the phone would be expecting this connection and would accept and play the resulting audio stream of synthesized text?  
    Any advise would be greatly appreciated.
    Thanks, Kirk



    Subject: RE: Stream Speech Data to Phone - Actively Refused
    Replied by: Jonathan Withers on 29-01-2010 10:49:25 AM
    I think the issue is to do with you sending the RTPRx from the server to the client. The easy way to test if this is the case is to setup a softkey that does the RTPRx call to the URL and then manually start the RTPTx.
    I would be very interested in seeing the SpeechSynthesizer and SpeechAudioFormat working as i've not been able to automatically send a voice message due to audio codec issues.
    If you need an example of the above then let me know

    Subject: RE: Stream Speech Data to Phone - Actively Refused
    Replied by: kirk moren on 29-01-2010 02:32:20 PM
    Thanks for the reply.  However, that doesn't appear to be the issue.    I started an active RTPRx session on the phone having it listening on port 31250 to the web server.   I then exercised the code above to stream the speech in G.711 u-law format to the listening phone but the socket.Connect method failed for the same reason, "No connection could be made because the target machine actively refused it.".   I've been able to do similar things such as send internet radio to the phone using a constantly running vlc (videolan) session to receive and transcode a stream to G.711 u-law (<font size="2" color="#a31515"><font size="2" color="#a31515">
    + phoneIP + ",port-audio=31250}) which worked but with poor sound quality so I'm not sure why this speech audio stream isn't working as well.