定制 commacodes/auto-convert-text-to-audio 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

commacodes/auto-convert-text-to-audio

最新稳定版本:v1.0.1

Composer 安装命令:

composer require commacodes/auto-convert-text-to-audio

包简介

Automatically converts multilingual text to audio and attaches it to your Laravel models.

README 文档

README

A Laravel package that automatically converts multilingual text to audio and attaches it to your models.

Requirements

PHP

This package requires PHP version 8.1 or higher, and is compatible with PHP versions 8.1, 8.2, and 8.3.

Laravel

This package is compatible with the following versions of Laravel:

  • Laravel 10.x

  • Laravel 11.x

  • Laravel 12.x

  • SSL Certificate

This Laravel package allows you to automatically convert multilingual content into audio files using Google Cloud Text-to-Speech.

Installation

composer require commacodes/auto-convert-text-to-audio

Then, publish the configuration file:

php artisan vendor:publish --tag=config

Usage

Move Your Google Service Account Json File to This Path and Rename It To "google-tts.json"

storage/app/google/google-tts.json

Add This Trait To Your Model "HasMultilangTTS"

<?php

namespace App\Models;

use commacodes\AutoConvertTextToAudio\Traits\HasMultilangTTS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;



class Post extends Model
{
    use HasFactory, HasMultilangTTS;

    protected $guarded = [];

}

Add the required columns to your model's database table

You need to add the necessary columns (audio_en, audio_fr, audio_ar) to your table:

Schema::table('your_model_table', function (Blueprint $table) {
    $table->string('audio_en')->nullable();
    $table->string('audio_fr')->nullable();
    $table->string('audio_ar')->nullable();
});

Add the following code to your Controller

Add the HasMultilangTTS trait to your Controller , call the generateTTS method to convert your multilingual text content into audio.

<?php

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\Http\Request;
use commacodes\AutoConvertTextToAudio\Traits\HasMultilangTTS;

class PostController extends Controller
{
    use HasMultilangTTS;

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $post = new Post();
        $post->name =   $request->name;
        $post->notes    =   ['en' => $request->notes, 'ar' => $request->notes_ar, 'fr' => $request->notes_fr];
        $post->save();
        $post->generateTTS([
            'ar' => $request->notes_ar,
            'en' => $request->notes,
            'fr' =>  $request->notes_fr,
        ]);
        return redirect()->route('post_index');
    }


}

To View MP3 Files

{{asset('upload/tts/'.$your_var->audio_en)}}
{{asset('upload/tts/'.$your_var->audio_ar)}}
{{asset('upload/tts/'.$your_var->audio_fr)}}

Made With Love By Comma Code Comapny Visit Us

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-13