Transcribe a voice conversation separate channels using Amazon Transcribe. This is done using PHP and Amazon Transcribe with an AWS Lambda function and AWS S3.
- PHP 7.4 (update
serverless.yml
for other versions) - Composer installed globally
- Node.js and npm
- Serverless Framework
- AWS account
- Vonage account
Clone this repo from GitHub, and navigate into the newly created directory to proceed.
This example requires the use of Composer to install dependencies and set up the autoloader.
Assuming a Composer global installation. https://getcomposer.org/doc/00-intro.md#globally
composer install
You will need to create AWS credentials as indicated by Serverless
.
Also, create a new AWS S3 bucket and make note of the URL for later use.
Create a new Vonage Voice application for this app, and associated it with a Vonage number.
Install the CLI by following these instructions. Then create a new Vonage Voice application that also sets up an answer_url
and event_url
for the app running in AWS Lambda.
Ensure to append /webhooks/answer
or /webhooks/event
to the end of the URL provided later by AWS Lambda, to coincide with the routes in index.php
.
nexmo app:create aws-transcribe https://<your_hostname>/webhooks/answer https://<your_hostname>/webhooks/event
NOTE: You will need to return to these settings to update after you know the URLs provided by deploying to AWS Lambda
IMPORTANT: This will return an application ID, and a private key. The application ID will be needed for the nexmo link:app as well as the .env file later, and create a file named private.key in the same location/level as server.js, by default, containing the private key.
If you don't have a number already in place, obtain one from Vonage. This can also be achieved using the CLI by running this command:
nexmo number:buy
Finally, link the new number to the created application by running:
nexmo link:app YOUR_NUMBER YOUR_APPLICATION_ID
Rename the provided .env.default
file to .env
and update the values as needed from AWS
and Vonage
.
APP_ID=voice-aws-transcribe-php
LANG_CODE=en-US
SAMPLE_RATE=8000
AWS_VERSION=latest
AWS_S3_ARN=<aws_s3_arn>
AWS_S3_BUCKET_NAME='<bucket_name>'
AWS_S3_RECORDING_FOLDER_NAME='<aws_s3_bucket_folder_name>'
NEXMO_APPLICATION_PRIVATE_KEY_PATH='./private.key'
NEXMO_APPLICATION_ID=<nexmo_application_id>
NOTE: All placeholders
<>
need to be updated.
Install the serverless-dotenv-plugin with the following command.
npm i -D serverless-dotenv-plugin
With all the above updated successfully, you can now use Serverless
to deploy the app to AWS Lambda.
serverless deploy
Note: Return to Nexmo and update the
answer
andevent
URLs with what is provided by the deployment.
With the deployment completed, you should be able to place a call to the Nexmo number
from any phone. You will hear a message about being connected, and the recipient
number will be called.
After you hang up, the MP3 file
will be retrieved from Nexmo
and uploaded to AWS S3
. Following that, a transcription job will be started. The job can be monitored in the AWS Console website after login.
As a follow-up, you may want to automate adding the results to a database. See this nexmo-community/aws-voice-transcription-rds-callback-php for more info on how to accomplish that.
We love questions, comments, issues - and especially pull requests. Either open an issue to talk to us, or reach us on twitter: https://twitter.com/VonageDev.