gm11
November 13, 2023, 4:56pm
1
Hi everyone, i'm new to arduino IDE, my problem is i got an erro "Audio is not defined" when i try to upload the code,
this is the code i copied from github
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "Audio.h"
const char* ssid = "SSID";
const char* password = "Password";
const char* chatgpt_token = "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";
const char* temperature = "0";
const char* max_tokens = "50";
String Question = "";
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26
Audio audio;
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
while (!Serial);
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(".");
}
Serial.println("connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(100);
}
void loop()
{
Serial.print("Ask your Question : ");
while (!Serial.available())
{
audio.loop();
}
while (Serial.available())
{
char add = Serial.read();
Question = Question + add;
delay(1);
}
int len = Question.length();
Question = Question.substring(0, (len - 1));
Question = "\"" + Question + "\"";
Serial.println(Question);
HTTPClient https;
//Serial.print("[HTTPS] begin...\n");
if (https.begin("https://api.openai.com/v1/completions")) { // HTTPS
https.addHeader("Content-Type", "application/json");
String token_key = String("Bearer ") + chatgpt_token;
https.addHeader("Authorization", token_key);
String payload = String("{\"model\": \"text-davinci-003\", \"prompt\": ") + Question + String(", \"temperature\": ") + temperature + String(", \"max_tokens\": ") + max_tokens + String("}"); //Instead of TEXT as Payload, can be JSON as Paylaod
//Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.POST(payload);
// httpCode will be negative on error
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
//Serial.println(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
String Answer = doc["choices"][0]["text"];
Answer = Answer.substring(2);
Serial.print("Answer : "); Serial.println(Answer);
audio.connecttospeech(Answer.c_str(), "en");
}
else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
else {
Serial.printf("[HTTPS] Unable to connect\n");
}
Question = "";
}
void audio_info(const char *info) {
Serial.print("audio_info: "); Serial.println(info);
}
horace
November 13, 2023, 5:01pm
2
you probably need to instal the Audio library
see installing-libraries
gm11
November 13, 2023, 5:05pm
3
i did that already, i installed the zip library
The library you need to install is this one:
horace
November 13, 2023, 5:17pm
7
reading the documentation for the Audio library it states
Allows playing audio files from an SD card. For Arduino Due only.
I assume as you are including WiFi.h etc you are attempting to run on a ESP32 or ESP8266
what do you wish to do?
try the library recommended by @cotestatnt
gm11
November 13, 2023, 5:18pm
8
if im not mistaken, we download the .zip file from github and add the .zip file to arduino IDE?
gm11
November 13, 2023, 5:19pm
9
i attempt to run on ESP32 Devkit V1
OK, but are you shure about the library?
You are using I2S, so you need the right library that can handle I2S as your sketch and not the first one named "Audio.h" you found on Google.
gm11
November 13, 2023, 5:23pm
11
so i'll have to download the I2S library ? ok lemme try
Yes, if you have an I2S DAC module offcourse
gm11
November 13, 2023, 5:28pm
13
I got a new error now.
'Audio' does not name a type
i already downloaded the libraries you sent. what should i do now?
I think it's time to stop, take a breath, and go back to the beginning.
Start with taking a few minutes to read How to get the best out of this forum .
Next:
Your board: provide a link to its technical data sheet or a link to where you bought it.
Your hardware: you're trying to play sound. Does your board have integrated sound capability? i.e. Is it just a matter of plugging a speaker in? Or do you have to use a separate sound board? If the latter, provide a link to its technical data sheet or a link to where you bought it.
Your code: provide a link to exactly where on Github it came from.
Your error: turn on "Show verbose output during compilation" and show us the whole output in <CODE>...</CODE> tags.
The library: the library recommended by @cotestatnt says, on its Github page: "This library only works on multi-core ESP32 chips like the ESP32-S3. It does not work on the ESP32-S2 or the ESP32-C3 ". Which processor is on your board?
1 Like
gm11
November 13, 2023, 6:03pm
15
ESP32 Devkit V1 is my board
b707
November 13, 2023, 6:44pm
16
gm11:
#include "Audio.h"
This line means that you have a file Audio.h
in the your sketch directory and can see the tab with this file in Arduino IDE.
If this a library, the include line must has another syntax:
#include <Audio.h>
gm11
November 13, 2023, 5:35pm
17
I had downloaded I2S and Audio libraries respectively and got the error message 'Audio' does not name a type. This is the code :
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "Audio.h"
const char* ssid = "SSID";
const char* password = "Password";
const char* chatgpt_token = "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";
const char* temperature = "0";
const char* max_tokens = "50";
String Question = "";
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26
Audio audio;
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
while (!Serial);
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(".");
}
Serial.println("connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(100);
}
void loop()
{
Serial.print("Ask your Question : ");
while (!Serial.available())
{
audio.loop();
}
while (Serial.available())
{
char add = Serial.read();
Question = Question + add;
delay(1);
}
int len = Question.length();
Question = Question.substring(0, (len - 1));
Question = "\"" + Question + "\"";
Serial.println(Question);
HTTPClient https;
//Serial.print("[HTTPS] begin...\n");
if (https.begin("https://api.openai.com/v1/completions")) { // HTTPS
https.addHeader("Content-Type", "application/json");
String token_key = String("Bearer ") + chatgpt_token;
https.addHeader("Authorization", token_key);
String payload = String("{\"model\": \"text-davinci-003\", \"prompt\": ") + Question + String(", \"temperature\": ") + temperature + String(", \"max_tokens\": ") + max_tokens + String("}"); //Instead of TEXT as Payload, can be JSON as Paylaod
//Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.POST(payload);
// httpCode will be negative on error
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
//Serial.println(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
String Answer = doc["choices"][0]["text"];
Answer = Answer.substring(2);
Serial.print("Answer : "); Serial.println(Answer);
audio.connecttospeech(Answer.c_str(), "en");
}
else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
else {
Serial.printf("[HTTPS] Unable to connect\n");
}
Question = "";
}
void audio_info(const char *info) {
Serial.print("audio_info: "); Serial.println(info);
}
The error message also give the line number. Where is it?
gm11
November 13, 2023, 5:43pm
19
it only says
exit status 1
'Audio' does not name a type
it is this one i think cuz its higlighted in red
Audio audio;
Did you down load the library that matches your Arduino board?