Syllable Counter API - Ruby Gem

Syllable Counter is a tool for counting syllables in words and text. It uses the CMU Pronouncing Dictionary for accurate syllable counting with rule-based fallback for unknown words.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_syllablecounter'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_syllablecounter

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_syllablecounter'

# Initialize the client
client = APIVerve::Syllablecounter::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ text: "The quick brown fox jumps over the lazy dog" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ text: "The quick brown fox jumps over the lazy dog" })
  puts response["data"]
rescue APIVerve::Syllablecounter::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Syllablecounter::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Syllablecounter::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "text": "The quick brown fox jumps over the lazy dog",
    "total_syllables": 11,
    "word_count": 9,
    "average_syllables_per_word": 1.22,
    "words": [
      {
        "word": "the",
        "syllables": 1
      },
      {
        "word": "quick",
        "syllables": 1
      },
      {
        "word": "brown",
        "syllables": 1
      },
      {
        "word": "fox",
        "syllables": 1
      },
      {
        "word": "jumps",
        "syllables": 1
      },
      {
        "word": "over",
        "syllables": 2
      },
      {
        "word": "the",
        "syllables": 1
      },
      {
        "word": "lazy",
        "syllables": 2
      },
      {
        "word": "dog",
        "syllables": 1
      }
    ]
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.