Consonant Counter API: The Complete Guide

Need to count consonants in text? This guide covers everything you need to know about consonant counting via API, including frequency analysis and linguistic applications.

What are Consonants?

Consonants are speech sounds produced with partial or complete closure of the vocal tract. In English, consonants are all letters except A, E, I, O, U (and sometimes Y). They include B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z.

Example: "Hello World" contains 7 consonants (H, l, l, W, r, l, d).

Consonant Analysis

Consonant analysis can provide:

  • Total count: Number of consonants in text
  • Frequency breakdown: Count per consonant letter
  • Consonant ratio: Percentage of characters that are consonants
  • Consonant clusters: Groups of consecutive consonants
Tip: Consonant-heavy text can be harder to pronounce. Analyzing consonant density helps assess text readability.

Using the Consonant Counter API

TinyFn provides a simple endpoint to count consonants:

API Request
POST https://api.tinyfn.io/v1/text/consonant-count
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "Hello World"
}
Response
{
  "total_consonants": 7,
  "breakdown": {
    "h": 1,
    "l": 3,
    "w": 1,
    "r": 1,
    "d": 1
  },
  "consonant_percentage": 70.0
}

Parameters

Parameter Type Description
text string The text to analyze (required)
include_y boolean Count Y as a consonant (default: true)
case_sensitive boolean Separate uppercase/lowercase counts (default: false)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/consonant-count',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ text: 'Hello World' })
  }
);
const result = await response.json();
console.log(result.total_consonants); // 7

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/consonant-count',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'Hello World'}
)
result = response.json()
print(result['total_consonants'])  # 7

cURL

curl -X POST "https://api.tinyfn.io/v1/text/consonant-count" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello World"}'

Common Use Cases

  • Language Learning: Teach consonant recognition
  • Phonetics Research: Analyze sound patterns
  • Word Games: Score based on consonant content
  • Text-to-Speech: Predict pronunciation difficulty
  • Linguistics: Compare languages by consonant usage

Best Practices

  1. Handle Y correctly: Y is typically counted as consonant at word start
  2. Consider language: Different languages have different consonant sets
  3. Normalize input: Usually count case-insensitively
  4. Provide breakdown: Show individual consonant counts

Try the Consonant Counter API

Get your free API key and start counting consonants in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key