dij-digital/deepgram-laravel

A Laravel package for integrating Deepgram’s AI voice services

v0.1.1 2025-08-16 15:57 UTC

This package is not auto-updated.

Last update: 2025-08-17 01:38:54 UTC


README

This package provides a seamless integration with Deepgram's AI voice services. Built following Laravel conventions.

This package supports the following features:

Speech-to-Text

  • Transcribe local audio files
  • Configurable transcription options (model, language, smart formatting)

Requires PHP 8.3 or higher and Laravel 12+

⚡️ Install the package using Composer:

composer require dij-digital/deepgram-laravel  

Configuration

Publish the config file:

php artisan vendor:publish --tag="deepgram-laravel-config"

Add your Deepgram API credentials to your .env file:

DEEPGRAM_API_KEY=your-api-key-here
DEEPGRAM_BASE_URL=https://api.deepgram.com/v1
DEEPGRAM_DEFAULT_MODEL=nova-2
DEEPGRAM_DEFAULT_LANGUAGE=en-US

How to use this package

Basic File Transcription

use DIJ\Deepgram\Facades\Deepgram;

// Basic transcription with config defaults
$result = Deepgram::listen()->transcribeFile('/path/to/audio.wav', 'audio/wav');

// With custom options per call
$result = Deepgram::listen()->transcribeFile('/path/to/audio.wav', 'audio/wav', [
    'model' => 'nova-3',
    'language' => 'en',
    'smart_format' => true,
    'punctuate' => true,
    'diarize' => true,
]);

Configuration Options

The published config file (config/deepgram-laravel.php) contains the following options:

return [
    'api_key' => env('DEEPGRAM_API_KEY'),
    'base_url' => env('DEEPGRAM_BASE_URL', 'https://api.deepgram.com/v1'),
    'default_model' => env('DEEPGRAM_DEFAULT_MODEL', 'nova-2'),
    'default_language' => env('DEEPGRAM_DEFAULT_LANGUAGE', 'nl'),

];

Testing

When testing your application, you can use Deepgram::fake() to prevent real HTTP calls to the Deepgram API:

use DIJ\Deepgram\Facades\Deepgram;

it('can process audio files', function () {
    // Prevent real API calls
    Deepgram::fake();
    
    // Your application code - no real HTTP calls will be made
    $result = Deepgram::listen()->transcribeFile('/path/to/audio.wav');
    
    // Returns fake transcription data for testing
    expect($result)->toBeArray()->toHaveKey('results');
});

The fake will return realistic fake transcription data so your tests can run without hitting the actual Deepgram API.

You can also use Laravel's standard facade mocking methods, like Deepgram::shouldReceive()->once()->andReturn() for more precise control if needed.

Deepgram Laravel was created by DIJ Digital under the MIT license.