We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

How to receive audio in a REST service?

Questions and answers about Plum Fuse+

Moderators: admin, support

Post Reply
zterlizzese
Posts: 9
Joined: Mon Nov 20, 2017 5:56 pm

How to receive audio in a REST service?

Post by zterlizzese »

Hello,

I have set up a REST service, and I am attempting to read the audio stream, but I am getting 0 bytes. Here is the call in C#:

Code: Select all

public string Read(Stream s)
        {
            string output = "No input";
            if (s != null)
            {
                output = "Input detected ";

                s.Seek(0, SeekOrigin.Begin);

                output += " | Type = " + s.GetType();

                output += " | Length = " + s.Length;

                int size = 0;
                byte[] b = new byte[1024];
                int bytesRead = 0;
                do
                {
                    bytesRead = s.Read(b, 0, b.Length);                    
                    size += bytesRead;
                } while (bytesRead > 0);

                if (size > 0)
                {
                    output = size + " bytes";
                }

                s.Close();
            }

            return "Read Result: " + output;
        }
This returns the following:

Code: Select all

Read Result: Input detected | Type = System.IO.MemoryStream | Length = 0
I am sending the data using the REST module with the type POST RAW and the only item in the body is the call_recording object (which was started for a few seconds then stopped).

So far I have tried to change the input to be a MemoryStream object, but that comes in as null. Any other suggestions to get this REST service to receive the audio?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: How to receive audio in a REST service?

Post by support »

Is there a particular reason you are using POST RAW and not a regular POST? We send call recordings as audio/x-wav. Here is an example of how to receive it via PHP:

Code: Select all

if (isset($_FILES['call_recording'])) {
  rename($_FILES['call_recording']['tmp_name'], "call_recording.wav");
}
We would recommend handling the call recording similarly to how you would handle other file uploads in C#.

zterlizzese
Posts: 9
Joined: Mon Nov 20, 2017 5:56 pm

Re: How to receive audio in a REST service?

Post by zterlizzese »

I'm sorry but I am still not able to use the downloaded file. I have tried the PHP code described using just the POST REST type. The resulting file does not play. I have opened the downloaded file in a hex editor, and I do not see any of the required bytes typical in a .wav file.

This is an example of the starting bytes in the file:

Code: Select all

ef bf bd ef bf bd ef bf bd ef bf bd
These are what are expected per WAVE file format:

Code: Select all

52 49 46 46 XX XX XX XX 57 41 56 45
Where the four middle bytes (XX XX XX XX) make up the data size.
Source: http://soundfile.sapp.org/doc/WaveFormat/

I've noticed that the pattern of "ef bf bd" appears repeatedly.

Is there some other encoding that I've not accounted for?

Thank you for your help,

Zachary

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: How to receive audio in a REST service?

Post by support »

Could you email us the resulting file? Please email to devsupport at plumgroup.com. We'd like to check up on it. Also could you let us know which application you are using to generate this file, and list step by step how to recreate the audio file?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: How to receive audio in a REST service?

Post by support »

First, we apologize for the huge confusion. Call recordings are sent in a .ul file format. Audio recordings done with the record module are in a .wav file format. Ideally, we would send all audio in the more common .wav format but due to platform constraints, call recordings must be in the raw .ul format.

We realize we have been mistakenly saying all recordings are in a .wav format multiple times in this support forum and we apologize for our mistake. The documentation has the correct information-- in that call recordings are .ul files, and we will take care that the support staff monitoring this forum are aware of their misunderstanding.

Post Reply