This guide will help you understand how to use a SurveyToGo code snippet to perform audio transcribing using the OpenAI API. We'll walk through the code, explain how it works, and show you how to adapt it to your needs.
Overview
In this guide we will discuss how to create a survey that uses OpenAI integration with user attachments.
1. Setting up a survey
2. Copy code to Advanced Scripts
3. Setting Up the OpenAI API Key
4. Using the script with Prompt and Image
5. Code overview and explanation
6. Customizing the request
Final Notes
Step-by-Step Guide
1. Setting up a survey
Before implementing the OCR functionality, you need to set up your survey in SurveyToGo with the following three questions:
-
First Question: Multimedia Question
- Type: Multimedia Question
- Purpose: To capture an audio recording that will be transcribed.
-
Identifier: Assign a unique identifier (e.g.,
Q_1
) to reference this question in your code.
-
Second Question: Waiting screen - Empty Question
- Type: Empty Question (Will show a waiting message)
- Purpose: Runs the transcribing function and shows the result.
-
Identifier: Assign a unique identifier (e.g.,
Q_2
) to reference this question in your code.
-
Third Question: Single choice for silent recording
-
Type: Single Choicen (e.g., Single Choice, Open-Ended)
- Purpose: Capture silent recording for transcribing
-
Identifier: Assign a unique identifier (e.g.,
Q_3
) if you need to manipulate it further in your code.
-
-
Fourth Question: Waiting screen - Empty Question
-
- Type: Empty Question (Will show a waiting message)
- Purpose: Runs the transcribing function and shows the result.
-
Identifier: Assign a unique identifier (e.g.,
Q_4
) if you need to manipulate it further in your code.
-
Survey structure
2. Copy code to Advanced Scripts
This code should be placed in the Advanced Scripts.
The advanced scripts will hold the function definition and callback functions neeeded for the implementation.
var secret = 'your_openai_api_key';
function Transcribe(QuestionID) {
var filename = GetAttachedFiles(QuestionID)[0];
var options = CreateWSOptions();
options.ContentType = "multipart/form-data";
options.Headers["Authorization"] = "Bearer " + secret;
options.Headers["Accept"] = "*/*";
options.FormData["model"] = "whisper-1";
options.FormData["file"] = "file://" + filename;
var res = WebServicePostSync("https://api.openai.com/v1/audio/transcriptions", null, options);
return res.Result
}
Comments
Article is closed for comments.