Text punctuation

Last updated: 2024-02-08Contributors
Edit this page

The Text Punctuation API takes a list of text blocks and augments them with proper punctuation using artificial intelligence. The same feature is applied to the speech recognition API's output if the enablePunctuation flag is set. The API will augment text with the following punctuation:

  • Periods, full-stop: .
  • Commas: ,
  • Quotes: ' "
  • Question marks: ?
  • Exclamation marks: !
  • Apostrophes: ', contractions and possessive forms
  • Proper capitalization, sentence-cap and acronyms

Augmenting text with proper punctuation

Request parameters

Parameter Type Description
texts List List of unformatted text blobs.

Sample code

The following example code shows how to provide the text paragraphs to the API and get the texts grammarly punctuated.

Follow the instructions on the quick start section to setup and run your server code before running the sample code below.

Running the code

  • Edit the variables in ALL CAPS with your app and user credentials before running the code.
  • You can only run on your production account, this means that you have to use app credentials for production.
const fs = require ('fs')
const RC = require('@ringcentral/sdk').SDK

// Instantiate the SDK and get the platform instance
var rcsdk = new RC({
    server: 'https://platform.ringcentral.com',
    clientId: 'PRODUCTION-APP-CLIENTID',
    clientSecret: 'PRODUCTION-APP-CLIENTSECRET'
});
var platform = rcsdk.platform();

/* Authenticate a user using a personal JWT token */
platform.on(platform.events.loginSuccess, () => {
    NGROK = "NGROK-TUNNEL-ADDRESS"
    WEBHOOK_URL = NGROK + "/webhook";
    punctuation()
})

platform.on(platform.events.loginError, function(e){
    console.log("Unable to authenticate to platform. Check credentials.", e.message)
    process.exit(1)
});

/*
* Add punctuation to text paragraphs
*/
async function punctuation() {
  try {
      let bodyParams = {
          texts: [
              "so its more fluid than it is and you know its not the best kind of feedback right",
              "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
              "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
          ]
      }
      let endpoint = `/ai/text/v1/async/punctuate?webhook=${WEBHOOK_URL}`
      let resp = await platform.post(endpoint, bodyParams)
      var jsonObj = await resp.json()
      if (resp.status == 202) {
        console.log("Job ID: " + jsonObj.jobId);
        console.log("Ready to receive response at: " + WEBHOOK_URL);
      }
  }
  catch (e) {
      console.log("Unable to call the punctuation API.", e.message)
  }
}
from ringcentral import SDK

NGROK = "NGROK-TUNNEL-ADDRESS"
WEBHOOK_URL = NGROK + "/webhook";

#
# Punctuate text paragraph
#
def punctuation():
    try:
        bodyParams = {
            'texts': [
                  "so its more fluid than it is and you know its not the best kind of feedback right",
                  "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
                  "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
              ]
          }
        endpoint = f'/ai/text/v1/async/punctuate?webhook={WEBHOOK_URL}'
        resp = platform.post(endpoint, bodyParams)
        jsonObj = resp.json()
        if resp.response().status_code == 202:
            print(f'Job ID: {resp.json().jobId}');
            print(f'Ready to receive response at: {WEBHOOK_URL}');
    except Exception as e:
        print ("Unable to call the punctuation API. " + str(e))


# Authenticate a user using a personal JWT token
def login():
  try:
      platform.login( jwt= "PRODUCTION-JWT" )
      punctuation()
  except Exception as e:
      print ("Unable to authenticate to platform. Check credentials. " + str(e))

# Instantiate the SDK and get the platform instance
rcsdk = SDK("PRODUCTION-APP-CLIENTID", "PRODUCTION-APP-CLIENTSECRET", "https://platform.ringcentral.com")
platform = rcsdk.platform()

login()
<?php
require('vendor/autoload.php');

// Instantiate the SDK and get the platform instance
$rcsdk = new RingCentral\SDK\SDK( 'PRODUCTION-APP-CLIENTID', 'PRODUCTION-APP-CLIENTSECRET', 'https://platform.ringcentral.com' );
$platform = $rcsdk->platform();

/* Authenticate a user using a personal JWT token */
$platform->login(["jwt" => 'PRODUCTION-JWT']);
$NGROK = "NGROK-TUNNEL-ADDRESS";
$WEBHOOK_URL = $NGROK . "/webhook";
punctuation();

/*
* Add punctuation to text paragraphs
*/
function punctuation()
{
  global $platform, $WEBHOOK_URL;
  try{
    $bodyParams = array (
        'texts' => array (
            "so its more fluid than it is and you know its not the best kind of feedback right",
            "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
            "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
        )
    );
    $endpoint = "/ai/text/v1/async/punctuate?webhook=" . urlencode($WEBHOOK_URL);
    $resp = $platform->post($endpoint, $bodyParams);
    $jsonObj = $resp->json();
    if ($resp->response()->getStatusCode() == 202) {
      print_r ("Job ID: " . $jsonObj->jobId . PHP_EOL);
      print_r("Ready to receive response at: " . $WEBHOOK_URL . PHP_EOL);
    }
  }catch (\RingCentral\SDK\Http\ApiException $e) {
    print_r ('Unable to call punctuation API. ' . $e->getMessage() . PHP_EOL);
  }
}
?>
require 'ringcentral'

NGROK = "NGROK-TUNNEL-ADDRESS"
WEBHOOK_URL = NGROK + "/webhook";

#
# Add punctuation to text paragraphs
#
def punctuation()
    begin
        bodyParams = {
            'texts': [
                  "so its more fluid than it is and you know its not the best kind of feedback right",
                  "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
                  "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
              ]
          }
        endpoint = "/ai/text/v1/async/punctuate?webhook=" + WEBHOOK_URL
        resp = $platform.post(endpoint, payload: bodyParams)
        body = resp.body
        if resp.status == 202
            puts('Job ID: ' + body['jobId']);
            puts ('Ready to receive response at: ' + WEBHOOK_URL);
        end
    rescue StandardError => e
        puts ("Unable to call the punctuation API. " + e.to_s)
    end
end


# Authenticate a user using a personal JWT token
def login()
  begin
      $platform.login( jwt= "PRODUCTION-JWT" )
      punctuation()
  rescue StandardError => e
      puts ("Unable to authenticate to platform. Check credentials. " + e.to_s)
  end
end

# Instantiate the SDK and get the platform instance
$platform = RingCentral.new( "PRODUCTION-APP-CLIENTID", "PRODUCTION-APP-CLIENTSECRET", "https://platform.ringcentral.com" )

login()
using System;
using System.IO;
using System.Threading.Tasks;
using System.Collections.Generic;
using RingCentral;
using Newtonsoft.Json;

namespace Punctuation {
  class Program {
    static string NGROK_ADDRESS = "NGROK-TUNNEL-ADDRESS";
    static string WEBHOOK_URL = NGROK_ADDRESS + "/webhook";

    static RestClient restClient;
    static async Task Main(string[] args){
      try
      {
        // Instantiate the SDK
        restClient = new RestClient("PRODUCTION-APP-CLIENT-ID", "PRODUCTION-APP-CLIENT-SECRET", "https://platform.ringcentral.com");

        // Authenticate a user using a personal JWT token
        await restClient.Authorize("PRODUCTION-JWT");

        await punctuation();
      }
      catch (Exception ex)
      {
        Console.WriteLine("Unable to authenticate to platform. Check credentials. " + ex.Message);
      }
    }
    /*
    * Add punctuation to text paragraphs
    */
    static private async Task punctuation()
    {
        try
        {
            var bodyParams = new PunctuateInput();
            bodyParams.texts = new String[] {
                "so its more fluid than it is and you know its not the best kind of feedback right",
                "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
                "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
            };
            var queryParams = new CaiPunctuateParameters() { webhook = WEBHOOK_URL};
            var resp = await restClient.Ai().Text().V1().Async().Punctuate().Post(bodyParams, queryParams);
            Console.WriteLine("Job ID: " + resp.jobId);
            Console.WriteLine("Ready to receive response at: " + WEBHOOK_URL);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unable to call punctuate API. " + ex.Message);
        }
    }
}
package Punctuation;

import java.io.IOException;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;

import com.ringcentral.*;
import com.ringcentral.definitions.*;

public class Punctuation {
    static String NGROK_ADDRESS = "NGROK-TUNNEL-ADDRESS";
    static String WEBHOOK_URL = NGROK_ADDRESS + "/webhook";

    static RestClient restClient;

    public static void main(String[] args) {
      var obj = new Punctuation();
      try {
        // Instantiate the SDK
        restClient = new RestClient("PRODUCTION-APP-CLIENT-ID", "PRODUCTION-APP-CLIENT-SECRET", "https://platform.ringcentral.com");

        // Authenticate a user using a personal JWT token
        restClient.authorize("PRODUCTION-JWT");

        obj.punctuation();

      } catch (RestException e) {
        System.out.println(e.getMessage());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    /*
    * Add punctuation to text paragraphs
    */
    static private void punctuation() throws RestException, IOException {
        try {
            var bodyParams = new PunctuateInput();
            bodyParams.texts = new String[] {
                "so its more fluid than it is and you know its not the best kind of feedback right",
                "and you know that the best way to ask for customer feedback is to reach out to each of your customer and interview them separately",
                "however interviewing each individual customer to get their feedback is not scalable if you have thousands of customers to be interviewed"
                };

            var queryParams = new CaiPunctuateParameters().webhook(WEBHOOK_URL);
            var resp = restClient.ai().text().v1().async().punctuate().post(bodyParams, queryParams);
            System.out.println("Job ID: " + resp.jobId);
            System.out.println("Ready to receive response at: " + WEBHOOK_URL);
        } catch (RestException ex) {
            System.out.println("Unable to call punctuate API. " + ex.getMessage());
        }
    }
}

Sample response

{
    "status": "Success",
    "response": {
        "texts":
        [
            "So it's more fluid than it is, and you know it's not the best kind of feedback, right?"
        ]
    }
}