def read_audio_segment(file_path, start_ms, end_ms):
    """
    Reads a segment from a WAV file and returns the raw data and its properties.

    :param file_path: Path to the WAV file.
    :param start_ms: Start time of the segment in milliseconds.
    :param end_ms: End time of the segment in milliseconds.
    :return: A tuple containing the raw audio data, frame rate, sample width, and number of channels.
    """
    #start_time = time.time()
    try:
        # Load the audio file
        audio = AudioSegment.from_wav(file_path)
        # Extract the segment
        segment = audio[start_ms:end_ms]
        # Get raw audio data
        raw_data = segment.raw_data
        # Get audio properties
        frame_rate = segment.frame_rate
        sample_width = segment.sample_width
        channels = segment.channels
        # Create NumPy array from the raw audio data
        audio_array = np.frombuffer(raw_data, dtype=np.int16)

        # If stereo, reshape the array to have a second dimension
        if channels > 1:
            audio_array = audio_array.reshape((-1, channels))
            audio_array = audio_array[...,0]
        '''
        if frame_rate !=48000:
            audio_array = audio_array/MAX_WAV_VALUE
            audio_array = librosa.resample(audio_array, frame_rate, 48000)
            audio_array = audio_array * MAX_WAV_VALUE
            frame_rate = 48000
        '''
        #end_time = time.time()
        #time_taken = end_time - start_time

        #print(f"Successfully read segment from {start_ms}ms to {end_ms}ms in {time_taken:.4f} seconds")
        return audio_array / MAX_WAV_VALUE#, frame_rate #, sample_width, channels
    except Exception as e:
        print(f"An error occurred: {e}")
        return None#, None #, None, None

    Reads a segment from a WAV file and returns the raw data and its properties.

    :param file_path: Path to the WAV file.
    :param start_ms: Start time of the segment in milliseconds.
    :param end_ms: End time of the segment in milliseconds.
    :return: A tuple containing the raw audio data, frame rate, sample width, and number of channels.
    
train/speech_super_resolution/dataloader/meldataset.py