Attaching DFplayer with a humidity sensor

I’m trying to get my DFplayer mini mp3 module to play certain sounds whenever a threshold range is reached by a humidity sensor. I’m using an Arduino micro so I’m wondering if I’m not using

 Serial.begin(9600);
  while (!Serial) ;

       Serial1.begin (9600);
         while (!Serial1) ;

properly.

/*************************************************** 
  This is an example for the HTU21D-F Humidity & Temp Sensor

  Designed specifically to work with the HTU21D-F sensor from Adafruit
  ----> https://www.adafruit.com/products/1899

  These displays use I2C to communicate, 2 pins are required to  
  interface
  
  // Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)

 ****************************************************/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Wire.h>
#include "SparkFunHTU21D.h"




//Create an instance of the object
HTU21D myHumidity;




int  updateDelay; // Milliseconds delay on changes



void setup() {
  Serial.begin(9600);
  while (!Serial) ;

       Serial1.begin (9600);
         while (!Serial1) ;
  updateDelay = 13; // Ms delay. Higher will be slower. Try 2 also.


// HUMIDITY SENSOR

  
  Serial.println("HTU21D-F test");

  myHumidity.begin();


  mp3_set_serial (Serial1);	//set Serial1 for DFPlayer-mini mp3 module 

    delay(1);                     // delay 1ms to set volume
    mp3_set_volume (25);          // value 0~30
    mp3_set_EQ (0);   //0~5
    
        mp3_play (1);

}

void loop() {

  
  
// HUMIDITY SENSOR 
  
  float humd = myHumidity.readHumidity();

  Serial.print("Time:");
  Serial.print(millis());
  Serial.print(" Humidity:");
  Serial.print(humd, 1);
  Serial.print("%");

  Serial.println();
  delay(1000);
  
  
      mp3_play (2);
      
      
      
      
       delay(8500);
      

       if (  humd < 50) {  //humidity threshold; change to suit your purpose

 
  } 
  
     if (humd > 90) {  //humidity threshold; change to suit your purpose
    mp3_play (3);

  } 

     if (  humd > 55 && humd < 80) {  //humidity threshold; change to suit your purpose
      mp3_play (4); 
  } 
  
  

  
  
  
    delay(6500);
}

A sensor cannot play sounds.

I think you need to rephrase your question.

Whether or not the while(Serial) statements are needed, or not, depends on which Arduino you are using, which you seem to have forgotten to mention.