Repository: ggerganov/whisper.cpp
File: examples/stream/stream.cpp (C++)

Code before:
        file.write("\0\0\0\0", 4);    // Placeholder for file size
        file.write("WAVE", 4);
        file.write("fmt ", 4);

        int32_t subChunkSize = 16;
        int16_t audioFormat = 1;      // PCM format
        int32_t byteRate = sampleRate * channels * bitsPerSample / 8;
        int16_t blockAlign = channels * bitsPerSample / 8;

        file.write(reinterpret_cast<char *>(&subChunkSize), 4);
        file.write(reinterpret_cast<char *>(&audioFormat), 2);
        file.write(reinterpret_cast<char *>(&channels), 2);
        file.write(reinterpret_cast<char *>(&sampleRate), 4);
        file.write(reinterpret_cast<char *>(&byteRate), 4);
        file.write(reinterpret_cast<char *>(&blockAlign), 2);
        file.write(reinterpret_cast<char *>(&bitsPerSample), 2);
        file.write("data", 4);
        file.write("\0\0\0\0", 4);    // Placeholder for data size
    }

    void writeData(const float *data, size_t length) {
        for (size_t i = 0; i < length; ++i) {
            int16_t intSample = static_cast<int16_t>(data[i] * 32767);
            file.write(reinterpret_cast<char *>(&intSample), sizeof(int16_t));
            dataSize += sizeof(int16_t);
        }
    }

    ~SimpleWavWriter() {
        if (file.is_open()) {
            file.seekp(4, std::ios::beg);
            int32_t fileSize = 36 + dataSize;
            file.write(reinterpret_cast<char *>(&fileSize), 4);
            file.seekp(40, std::ios::beg);
            file.write(reinterpret_cast<char *>(&dataSize), 4);
            file.close();
        }
    }
};
//  500 -> 00:05.000
// 6000 -> 01:00.000
std::string to_timestamp(int64_t t) {
    int64_t sec = t/100;
    int64_t msec = t - sec*100;
    int64_t min = sec/60;
    sec = sec - min*60;

    char buf[32];
    snprintf(buf, sizeof(buf), "%02d:%02d.%03d", (int) min, (int) sec, (int) msec);

    return std::string(buf);

Review comment (suggestion):
```suggestion
    void writeData(const float *data, size_t length) {
        for (size_t i = 0; i < length; ++i) {
            int16_t intSample = static_cast<int16_t>(data[i] * 32767);
            file.write(reinterpret_cast<char *>(&intSample), sizeof(int16_t));
            dataSize += sizeof(int16_t);
        }
        if (file.is_open()) {
            file.seekp(4, std::ios::beg);
            int32_t fileSize = 36 + dataSize;
            file.write(reinterpret_cast<char *>(&fileSize), 4);
            file.seekp(40, std::ios::beg);
            file.write(reinterpret_cast<char *>(&dataSize), 4);
            file.seekp(0, std::ios::end);
        }
    }
```

Code after:
        file.write("\0\0\0\0", 4);    // Placeholder for file size
        file.write("WAVE", 4);
        file.write("fmt ", 4);

        int32_t subChunkSize = 16;
        int16_t audioFormat = 1;      // PCM format
        int32_t byteRate = sampleRate * channels * bitsPerSample / 8;
        int16_t blockAlign = channels * bitsPerSample / 8;

        file.write(reinterpret_cast<char *>(&subChunkSize), 4);
        file.write(reinterpret_cast<char *>(&audioFormat), 2);
        file.write(reinterpret_cast<char *>(&channels), 2);
        file.write(reinterpret_cast<char *>(&sampleRate), 4);
        file.write(reinterpret_cast<char *>(&byteRate), 4);
        file.write(reinterpret_cast<char *>(&blockAlign), 2);
        file.write(reinterpret_cast<char *>(&bitsPerSample), 2);
        file.write("data", 4);
        file.write("\0\0\0\0", 4);    // Placeholder for data size
    }

    void writeData(const float *data, size_t length) {
        for (size_t i = 0; i < length; ++i) {
            int16_t intSample = static_cast<int16_t>(data[i] * 32767);
            file.write(reinterpret_cast<char *>(&intSample), sizeof(int16_t));
            dataSize += sizeof(int16_t);
        }
        if (file.is_open()) {
            file.seekp(4, std::ios::beg);
            int32_t fileSize = 36 + dataSize;
            file.write(reinterpret_cast<char *>(&fileSize), 4);
            file.seekp(40, std::ios::beg);
            file.write(reinterpret_cast<char *>(&dataSize), 4);
            file.seekp(0, std::ios::end);
        }
    }

    ~SimpleWavWriter() {
        if (file.is_open()) {
            file.close();
        }
    }
};
//  500 -> 00:05.000
// 6000 -> 01:00.000
std::string to_timestamp(int64_t t) {
    int64_t sec = t/100;
    int64_t msec = t - sec*100;
    int64_t min = sec/60;
    sec = sec - min*60;

    char buf[32];