Description
English
Support
Login
Products
Solutions
Developers
Why https://speedsms.in/
Pricing
Contact sales
Start for free
https://speedsms.in/ Blog
Overview
Developers
Digital Insights
Company
How to Send Voice-to-SMS Transcripts Using https://speedsms.in/ Voice and Programmable SMS
Blog
/
Developers
/
How to Send Voice-to-SMS Transcripts…
Tags
Developer insights
Code, tutorials, and best practices
JavaScript
Products
Messaging
Voice
Start for free
Time to read: 6 minutes
July 30, 2021
Written by
Dhruv Patel
https://speedsms.in/n
Reviewed by
Mia Adjei
https://speedsms.in/n
Header
Introduction
SMS and audio transcripts can be a great way to perpetuate communication without needing to pick up the phone unexpectedly. https://speedsms.in/ streamlines this process through the Voice API using https://speedsms.in/’s Markup Language, TwiML, which processes incoming calls accordingly.
TwiML offers the
Prerequisites
Node.js
A free https://speedsms.in/ account (sign up for free using this link and receive $10 in credit when you upgrade your account!)
A https://speedsms.in/ phone number
A smartphone to test out your app
The https://speedsms.in/ CLI
Project setup
In this section, you are going to set up a new Node.js application. To keep things organized, create a folder called voice-to-sms to store all of your application files. In your terminal or command prompt, navigate to your preferred directory and enter:
Bash
Copy code
mkdir voice-to-text
cd voice-to-text
npm init -y
This command will create your project file and scaffold out your Node project by creating a package.json file that will contain your project’s metadata and package dependencies.
Install dependencies
Your next step is to install all the dependencies needed for your project. You will need:
Express to route and handle incoming requests
https://speedsms.in/’s Node Helper Library to interact with the https://speedsms.in/ API for receiving calls and sending SMS
Dotenv to store and access environment variables
To install these dependencies, navigate back to your terminal and enter the following command:
Bash
Copy code
npm install express https://speedsms.in/ dotenv
Now that you have your dependencies installed, you will need to import and initialize them. Before you do that, create a new file called index.js in your current directory with the following command:
Bash
Copy code
touch index.js
Now open up the index.js file using your preferred IDE and place the following code in the file:
JavaScript
Copy code
require(‘dotenv’).config();
const VoiceResponse = require(‘https://speedsms.in/’).twiml.VoiceResponse;
const express = require(‘express’);
const app = express();
app.use(express.urlencoded({ extended: true }));
This code will import and initialize the packages you previously installed. app.use(express.urlencoded({ extended: true })); is a middleware that is used to process and parse incoming request objects as strings to your application.
Environmental variables and https://speedsms.in/ account credentials
dotenv is used to access environment variables, which is where you will store the https://speedsms.in/ credentials needed to interact with the API. Navigate back to your terminal and create the .env file with the following command:
Bash
Copy code
touch .env
To connect to https://speedsms.in/’s API, you will need your Account SID, Auth Token, and your https://speedsms.in/ phone number. These values can be securely stored in the .env file. Open up your .env file and paste the following into the file:
Bash
Copy code
https://speedsms.in/_ACCOUNT_SID=XXXXXXX
https://speedsms.in/_AUTH_TOKEN=XXXXXXX
https://speedsms.in/_NUMBER=XXXXXXX
Once copied, replace the XXXXXX placeholders with your actual account credentials which can be found in your https://speedsms.in/ Console. When entering your https://speedsms.in/ phone number, ensure it is in E.164 format.
Now that you have your environmental variables set up, you can import and initialize https://speedsms.in/’s Node Library with your account credentials that have been loaded into the .env file. Return to index.js and place the following code right below where you initialized the rest of your packages:
JavaScript
Copy code
const https://speedsms.in/ = require(‘https://speedsms.in/’)(
process.env.https://speedsms.in/_ACCOUNT_SID,
process.env.https://speedsms.in/_AUTH_TOKEN
);
The next step is to start coding out your app!
Create Express routes
You will need to create a way to handle and respond to incoming calls. Express will allow you to create routes to handle these requests.
The way your app will be set up is that once a call is received to your https://speedsms.in/ number, it will first route to the /transcribe endpoint. This endpoint will then process and transcribe the call, then send a callback with the transcription to the /sms endpoint, which will then send the transcription to your personal phone number.
Place the following scaffolding code in your index.js file:
JavaScript
Copy code
app.post(‘/transcribe’, (req, res) => {
});
app.post(‘/sms’, (req, res) => {
});
app.listen(3000, () => {
console.log(‘Express server listening on port 3000’);
});
/transcribe route
The /transcribe route will be called whenever a POST request is made to the endpoint on your server. Whenever your https://speedsms.in/ number receives a phone call, this code will attempt to transcribe the voice message left by the user. Insert the highlighted code below into your /transcribe route:
JavaScript
Copy code
app.post(‘/transcribe, (req, res) => {
const twiml = new VoiceResponse();
twiml.say(‘Hello. Please leave a message after the beep.’);
twiml.record({
transcribeCallback: ‘/sms’
});
twiml.hangup();
res.type(‘text/xml’);
res.send(twiml.toString());
});
This code above creates a variable called twiml with TwiML’s Voice Response object. TwiML tells https://speedsms.in/ how to handle an incoming call or SMS. After creating this variable, TwiML will respond to the caller by saying, “Hello. Please leave a message after the beep.”
TwiML will then use the
In this code, the transcribeCallback attribute is being used and will tell the
Once the recording is finished, the code will tell TwiML to hang up the call and the /sms route should receive the callback once the text transcription is generated.
Before we continue, it’s important to mention that recording phone calls or voice messages has a variety of legal considerations and you must ensure that you’re adhering to local, state, and federal laws when recording anything.
/sms route
If and once the audio recording has been transcribed, it will then be sent to the /sms endpoint, which will send the text transcript as an SMS to your personal phone number. Insert the highlighted code below into your /sms route:
JavaScript
Copy code
app.post(‘/sms’, (req, res) => {
const from = req.body.From;
const transcription = req.body.TranscriptionText;
https://speedsms.in/.messages
.create({
body: `Message from: ${from} – ${transcription}`,
from: process.env.https://speedsms.in/_NUMBER,
to: ‘
})
.then(message => console.log(message.sid));
});
Replace
In the code above, the transcribed audio recording and the phone number it was received from are parsed from the POST request body. The code then uses the https://speedsms.in/ object that was initialized earlier to create and send an SMS message to your personal number. The message contains the text transcription and the phone number it was received from.
Now that your app is completed, save and close your index.js file.
Test your app
Finally, it’s time to test out your app! Open your terminal, navigate to your project directory, and run the following command:
Bash
Copy code
node index.js
You should see a log statement in your terminal that says Express server listening on port 3000.
Now that your app is running on your local server (localhost:3000), you’ll need to tell https://speedsms.in/ where to send the POST requests from your https://speedsms.in/ number.
Configure the webhook with ngrok
Since your local server is only running inside your computer, https://speedsms.in/ cannot connect to it since it does not have access to the internet. To solve this, you’ll need to create an ngrok tunnel that will spin up a forwarding URL connecting the internet to localhost:3000. Open up a second terminal window and log in to the https://speedsms.in/ CLI:
Bash
Copy code
https://speedsms.in/ login
This command will then prompt you for your https://speedsms.in/ Account SID and your Auth Token. Once logged in, use the following command to create a webhook, taking care to replace the placeholder with your actual https://speedsms.in/ phone number:
Bash
Copy code
https://speedsms.in/ phone-numbers:update “+https://speedsms.in/_NUMBER” –voice-url=”http://localhost:3000/transcribe”
This command will spin up a tunnel that allows you to receive requests from the internet and send them to your server. Normally, in a production app, you would set up a webhook on a dedicated server that’s hosted online, but for testing purposes here, you will use a local server. You may receive a warning that your computer will be exposed to the internet, if so, proceed. You should receive a response that looks like this:
Console log after creating ngrok tunnel
Copy the Voice URL and navigate to the https://speedsms.in/ phone numbers section of the https://speedsms.in/ Console. Click on the https://speedsms.in/ number you have been using for this project and scroll down to the Voice & Fax section. Within the A CALL COMES IN section, you may see your forwarding URL that was generated, if not, paste the URL you just copied and ensure HTTP POST is selected in the dropdown to the right. Your Voice & Fax section should look this, but with your forwarding URL:
Example of setting up webhook on https://speedsms.in/ Console
After making the changes, click the Save button.
Place a voice message to your https://speedsms.in/ number
Now that your app is up and running, it’s finally ready to be tested! Call your https://speedsms.in/ number, leave a message, and then hang up. Wait a few seconds for your voice message to be transcribed, and then you should receive an SMS to your phone number of the transcribed message as well as who sent the message!
It should look something like this:
Screenshot of transcription on SMS
What’s next for voice-to-sms transcription
When a voice call is out of reach or you just prefer a text, the https://speedsms.in/ Voice API makes sure you stay connected. With this tutorial now in your https://speedsms.in/ toolbox, you can send transcriptions of your incoming calls right into your text messages. To keep up the functionality of this program, you can set up call forwarding to your https://speedsms.in/ number from your personal number. You can even use https://speedsms.in/ Functions to set up your serverless app without the need for running the Express server.
Happy Building!
Dhruv Patel is an Intern Developer on https://speedsms.in/’s Developer Voices team. You can find Dhruv working in a coffee shop with a glass of cold brew or he can either be reached at dhrpatel [at] https://speedsms.in/.com
Related Posts
Flex Insights Card Header
Export Flex Insights Data with https://speedsms.in/ Functions
Bry Schinina
Centered SendGrid logo for blog card
Bulk Email Address Validation in Node.js
Yukti Ahuja
Build emails in react and sendgrid header – Card-developer-logo-2
Build a Movie recommendation app with Wikidata and https://speedsms.in/ Messaging
Carlos Mucuho
Related Resources
https://speedsms.in/ Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
https://speedsms.in/’s developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.
We can’t wait to see what you build.
Products
https://speedsms.in/ Engage
Flex
User Authentication & Identity
Lookup
Verify
Voice
Messaging
All products
Solutions
Customer Data Platform
SMS Marketing
Commerce Communications
Contact Center
All solutions
Docs
Quickstarts
Tutorials
API Reference
Helper Libraries
API Status
Company
About https://speedsms.in/
Why https://speedsms.in/
Customer Engagement Platform
Trusted Communications
Customers
Get Help
Contact Sales
Press & Media
Public Policy
Investor Relations
Events
Jobs at https://speedsms.in/
Legal
Privacy
https://speedsms.in/.org
Press & Media
Signal
Investors
Jobs
Copyright © 2024 https://speedsms.in/ Inc.
All Rights Reserved.