In this guide, we’ll demonstrate how to create a seamless user experience by converting speech into site content using Groq and Netlify. We’ll cover the integration between APIs, briefly discuss configuring the Visual Editor, and show how to connect all the dots.
#TL;DR
We’ll walk you through building a speech-to-content integration for your website. You’ll learn how to combine Groq’s AI capabilities with Netlify’s backend services to manage and update site content.
#Tech Stack overview
We’ll use the following technologies:
- Astro as the site framework
- Markdown files for the content source
- Netlify Functions for handling API requests
- Netlify Visual Editor to manage content
- Groq to convert speech into text
Note: this functionality can be implemented with any site framework. We’re using Astro as an example.
#Setup
Let’s get you setup before diving into the code.
#Groq API key
Before you begin, you will need a Groq account. Sign up at Groq Console and generate an API key.
#Deploy to Netlify
With your Groq API key ready, click the button below to deploy the example to your Netlify account. This process will prompt you to enter your Groq API key.
#Enable visual editing
To make visual editing work properly for your Netlify Site, you must first add the API_HOST
environment variable. This should be the URL of your deployed site. You can set this in the Netlify UI under Site settings > Build & deploy > Environment
.
Then you’re ready to enable visual editing. Go to Site configuration > Visual Editor
and select Enable visual editing
.
#Test it!
At this point the site is deployed and the Visual Editor is enabled. You can now navigate to the visual editor from the site overview in the Netlify UI or in your site configuration, by choosing Open visual editor
(1) or the Visual editor
link (2).
Open the content editor for the page and you’ll be able to record your voice and see the content update in real-time.
#Running the project locally
If you’d like to get the project running locally, you can clone the repo that was added to your GitHub account and navigate to the example:
#Start development server
To get the project running locally, first install the Netlify CLI.
Then install the project dependencies:
Start the Astro dev server with Netlify Dev and specify the target port:
This starts the Astro site with all Netlify features automatically enabled.
#Build custom field code
As we’ll see below, we’re using a custom field for the speech-to-text feature. To build the custom field code, run the following commands:
If Netlify Dev started on a different port, make sure to update the API_HOST
value accordingly.
#Start visual editor server
With Netlify Dev running, install the visual editor CLI:
And now you’re ready to run the visual editor locally. Remember to keep the Netlify Dev server running.
This will print out a URL where you can access the visual editor. And now you’re all set to test the speech-to-text feature locally!
#How speech-to-content works
With the setup complete, let’s dive into the code and understand how the speech-to-content feature works.
#Netlify Functions
The Netlify Function in the netlify/functions
directory is responsible for converting speech to text.
It expects to receive an audio file as a payload and passes it to Groq via their SDK with other LLM configurations. And once the audio is transformed to text, the function responds with the result.
With this function, the API will be available via /api/speech-to-text
.
#Visual editor configuration
The visual editor configuration file adds some custom configuration that, aside from the basics, does a few key things:
- Ensures the custom fields are built before starting the visual editor server (in production)
- Custom configuration to ensure Astro works correctly
- Adds a single content model for the page, which is imported from the
.stackbit/models
directory
#Page model
The content model schema for the page is placed in .stackbit/models
. It has a simple content schema that defines a title
fields, along with a text
field that is used for the speech-to-text feature.
#Custom field
Custom fields for the visual editor are mini applications that tap into visual editor content hooks. We won’t go through that in detail. If you’d like to dig into, you can find the custom field code in the .stackbit/custom-controls
directory.
At a high level, the custom field is presents a media recorder that holds onto the audio file and sends it to the Netlify Function for processing.
#Apply this to your site!
Taking direct audio input and modifying a web page unlocks so many opportunities. With Groq’s extensive capabilities and industry-leading performance, the possibilities are endless for enhancing your site’s experience on Netlify and taking it to the next level.