# Use Plum's Transcription API

There are two components in DEV: the VoiceXML script and the PHP script.

The VXML script contains the text that the caller will hear. The PHP script handles all the backend processes and API calls. The PHP initiates when the VXML script gets to the *\<subdialog>* tag.

The first prompt (lines 5-7) mirrors the prompt module in the Fuse app. In the following section (starting on line 12), you can see the counterpart to the record module. Here the name of the audio file is set to *myrecording*.

```xml
<?xml version="1.0"?>
<vxml version="2.1">
  <form>
   <block>
    <prompt>
      The following is an example of prompting a caller to leave a recorded message, then sending that message to our real-time-transcription API, and finally have the system read back the transcription as TTS.
    </prompt>
   <goto next="#record"/>
   </block>
  </form>

  <form id="record">
    <var name="callrecording"/>
    <record name="myrecording" beep="true">
      <prompt>
        Please leave a recorded message after the beep. When you are done recording, press the pound key.
      </prompt>
      <filled>
	<assign name="callrecording" expr="myrecording"/>
      </filled>
    </record>
   <subdialog name="transcription" src="subdialog.php" namelist="callrecording" method="post" enctype="multipart/form-data"/>
     <block>
	  We transcribed your message as, <value expr="transcription.message"/>.
     </block>	
  </form>
</vxml>
```

The API call starts at the *\<subdialog>* tag. Looking at the subdialog.php script, you can see that both the language and audio form data parameters get set in the **`$post = array`** section (starting on Line 10).

{% code title="subdialog.php" %}

```php
<?php
header("Content-type: text/xml");
echo("<?xml version=\"1.0\"?>\n");
​
$ch = curl_init();
​
curl_setopt($ch, CURLOPT_URL, 'https://hosting.plumvoice.com/ws/transcription/transcribe.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
        'language' => 'en-US',
        'audio' => new CURLFILE($_FILES['callrecording']['tmp_name'])
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode('username:password')));
​
$result = curl_exec($ch);
if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$data = json_decode($result);
$message = $data->result->message;
​
?>
<vxml version="2.0">
  <form>
    <block>
      <var name="message" expr="'<?php echo("$message")?>'"/>
      <return namelist="message"/>
    </block>
  </form>
</vxml>
```

{% endcode %}

Using this method, you can encode your DEV credentials in base 64, just like the Fuse example above, and use them in the API call.

Simply replace the 'username:password' value in the code in line 15 with your base 64 string.

Using the same info from the Fuse example, the updated code in line 15 would look like this:

`curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic RnVzZVVzZXI6MTIzNDU='));`

The `$result` section (starting on line 17) checks to make sure everything occurred as intended. If everything checks out, it provides the variable names for the VXML script, otherwise it logs an error.

Looking back at the VXML script (line 23), you can see that the app reads back the text of the transcription, indicated here by the variable *transcription.message*.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.plumvoice.com/dev/developer-reference/how-to/use-plums-transcription-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
