PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Mr.shaggyy83   ChatGPT Text and Speech Converter   index.php   Download  
File: index.php
Role: Application script
Content type: text/plain
Description: Auxiliary script
Class: ChatGPT Text and Speech Converter
Convert text to audio and generate audio from text
Author: By
Last change:
Date: 1 month ago
Size: 4,871 bytes


Class file image Download
include 'function.php';

$apiKey = "";



if (isset(
$_POST['submit'])) {


//if selected Ask Question
if (!empty($_POST['answ']) && empty($_POST['text'] && !empty($apiKey))) {

$message = $_POST['answ'];




//if selected Write or Copy Text:
if (!empty($_POST['text']) && empty($_POST['answ']) && !empty($apiKey)) {



//if selected speech to text
if ($output==true && empty($_POST['text']) && empty($_POST['answ'] && !empty($apiKey)) ) {


$path = 'upload';
$files = scandir($path);
foreach (
$files as $filename ) {




define("UPLOAD_DIR", "upload/");
if (isset(
$_POST["send"])) {

$countfiles = $_FILES['file']['name'];

$filename = $_FILES['file']['name'];

$total_size= filesize($filename);

//26214400 -- 25MB

if ($total_size<='26214400') {
# code...
$location = "upload/".$filename;
$extension = pathinfo($location,PATHINFO_EXTENSION);
$extension = strtolower($extension);

## File upload allowed extensions
$valid_extensions = array("mp4","mpeg","mpga","m4a","wav","webm", "mp3");

## Check file extension
if(in_array(strtolower($extension), $valid_extensions)) {
## Upload file




<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>

  <script src="js/jquery-3.6.0.min.js" defer></script>
    <script src="js/jquery.form.min.js" defer></script>
    <script src="js/script.js" defer></script>
      <link rel="stylesheet" href="css/style.css" />

        audio::-webkit-media-controls {

if ( $output_folder==false) {
"display: none;";


<div class="container">
  <h2>ChatGPT Text To Speech</h2>
  <form action="" method="POST" enctype='multipart/form-data'>
    <div class="form-group">
      <label for="answ">Ask Question:</label>
      <input type="text" class="form-control" id="answ" name="answ">
    <div class="form-group">
      <label for="pwd">Write or Copy Text:</label>
       <textarea class="form-control" rows="5" id="text" name="text"></textarea>
       <label for="pwd">Output Formats:</label>
       <select id="Formats" name="Formats">
    <option value="mp3">mp3</option>
    <option value="aac">aac</option>
    <option value="flac">flac</option>
    <option value="pcm">pcm</option>
       <button type="submit" class="btn btn-primary" name="submit">Submit</button><br>
       <audio controls>
   <?php echo '<source src="output_speech/'.$get_filename.'" type="audio/mpeg">'?>

    <form action="" method="POST" enctype='multipart/form-data' id="form">
    <div class="container">
        <div class="form-wrapper">
            <h2>Speech To Text</h2>
            <div class="file-input">
                <input type="file" name="file" id="btn-chose" style="display:none" />

              <label class="custom-file" for="btn-chose">Choose File</label>

              <span id="file-chosen" value="nochosen"> </span>
              <button class="btn btn-primary" type="submit" name="send" id="sendbtn">Send File</button>

          <div class="uploading-status hidden">
            <div class="progress-bar" id="uploadingProgress"></div>
                <strong><h5>Total Size:</h5></strong>
                <span id="totalSize"></span>