-
Google Cloud Account:
- Enable the Speech-to-Text API and Text-to-Speech API in the Google Cloud Console.
- Create a service account key in JSON format and download it.
-
OpenAI API Key:
- Sign up for OpenAI and get your OpenAI API Key for accessing the ChatGPT API.
-
PHP Composer:
- Install Composer to manage dependencies:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
- Install Composer to manage dependencies:
To interact with Google Cloud APIs (Speech-to-Text and Text-to-Speech), install the required libraries:
composer require google/cloud-speech
composer require google/cloud-text-to-speech
After downloading your service account key from the Google Cloud Console, set up the credentials using the following command:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-account-file.json"
- Make sure to have the OpenAI API Key handy.
- The script uses PHP
cURL
to communicate with the OpenAI API.
-
Install Composer and the necessary Google Cloud libraries for Speech and Text-to-Speech.
composer require google/cloud-speech composer require google/cloud-text-to-speech
-
Set the Google Cloud credentials environment variable:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-account-file.json"
-
Download or copy the PHP script and place it in a directory on your server or local machine.
-
Modify the script to include your OpenAI API key and ensure the path to your Google Cloud JSON file is set.
-
Create the
uploads/
directory where uploaded audio files will be saved. -
Run the script in your local server or hosting environment.
-
Access the form via a browser, upload an audio file, and test the interaction.
-
Voice Input:
- Use the form to upload an audio file (
.wav
,.mp3
, etc.). - The script will transcribe the audio using Google Cloud Speech-to-Text.
- Use the form to upload an audio file (
-
ChatGPT Response:
- The transcribed text will be sent to ChatGPT via the OpenAI API.
- The response from ChatGPT will be displayed as text.
-
Text-to-Speech Output:
- The ChatGPT response will be converted back to speech using Google Cloud Text-to-Speech.
- An audio player will allow you to listen to the ChatGPT response, and an option to download the audio will be provided.
- Ensure that your Google Cloud Credentials are set correctly.
- Make sure the audio file is of a supported format and matches the required sample rate and encoding.
- Double-check your OpenAI API Key is valid and has sufficient quota.
- Review file permissions on the
uploads/
folder to ensure the script can save files there.
I put a lot of work into these scripts so please donate if you can. Even $1 helps!
PayPal: alex@alexandermirvis.com
CashApp / Venmo: LynxGeekNYC
BitCoin: bc1q8sthd96c7chhq5kr3u80xrxs26jna9d8c0mjh7