'player' does not name a type

İ am trying to use an mp 3 player but it gives the error. 'player' does not name a type
Please help. Here is my code.

#include "SoftwareSerial.h"
#include "VoiceRecognitionV3.h"
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini player;
VR myVR(4,5); // 2:RX 3:TX, you can choose your favourite pins.
uint16_t records[7];
uint16_t buf[64];
int led = 13;
#define onRecord (0)
#define offRecord (1)
void printSignature(uint16_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf[i]>0x19 && buf[i]<0x7F){
Serial.write(buf[i]);
}
else{
Serial.print("[");
Serial.print(buf[i], HEX);
Serial.print("]");
}
}
}

void printVR(uint16_t *buf)
{
Serial.println("VR Index\tGroup\tRecordNum\tSignature");

Serial.print(buf[2], DEC);
Serial.print("\t\t");

if(buf[0] == 0xFF){
Serial.print("NONE");
}
else if(buf[0]&0x80){
Serial.print("UG ");
Serial.print(buf[0]&(~0x80), DEC);
}
else{
Serial.print("SG ");
Serial.print(buf[0], DEC);
}
Serial.print("\t");

Serial.print(buf[1], DEC);
Serial.print("\t\t");
if(buf[3]>0){
printSignature(buf+4, buf[3]);
}
else{
Serial.print("NONE");
}
Serial.println("\r\n");
}
static const uint16_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint16_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
void yeni()
{
if (player.begin(softwareSerial)) {
Serial.println("OK");

}

}

void setup()
{
/** initialize */
myVR.begin(9600);
softwareSerial.begin(9600);
Serial.begin(9600);
// Init USB serial port for debugging

Serial.begin(115200);
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");

pinMode(led, OUTPUT);
player.volume(30);
if(myVR.clear() == 0){
Serial.println("Recognizer cleared.");
}else{
Serial.println("Not find VoiceRecognitionModule.");
Serial.println("Please check connection and restart Arduino.");
while(1);
}

if(myVR.load((uint16_t)offRecord) >= 0){
Serial.println("offRecord loaded");
}
}

// Start communication with DFPlayer Mini

// Set volume to maximum (0 to 30).
player.volume(30);
// Play the first MP3 file on the SD card
player.play(1);

} else {
Serial.println("Connecting to DFPlayer Mini failed!");
}
}
void loop()
{
int ret;
ret = myVR.recognize(buf, 1);
if(ret>0){
switch(buf[1]){
case onRecord:
player.play(1);
break;
}
/** voice recognized */
printVR(buf);
}
}

// if(myVR.load((uint16_t)onRecord) >= 0){
// Serial.println("onRecord loaded");

Just a few things:
This is not an installation and troubleshooting topic.
Please remember to use code tags when posting code.
Please remember to copy and post all the error messages

sorry i am new

Please read How to get the best out of this forum and apply what you learned about posting code to your opening post.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Posting well formatted code

Posting all detail-information about compiler-errors

Be the change you want to see in the world
best regards Stefan

You can't have executable code, like function calls, outside a function. Don't put the final '}' of setup() until AFTER all the code in setup().

}  //////// setup() ends here ////////////

// Start communication with DFPlayer Mini

// Set volume to maximum (0 to 30).
player.volume(30);
// Play the first MP3 file on the SD card
player.play(1);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.