Always interesting doing a cassette tape emulation.
If you really want to get down in the mud, you could encode and decode audio streams via a sound interface - a whole lot of work for something few people will care that much about.
If you're "lucky" the tape interface will present as some sort of digital data at the software end.
The only tape interface I actually implemented was for my H8 emulator of the Heathkit H8 system.
Fortunately the H8-5 card (Serial/Cassette tape interface) just had tone generators and decoders on it so that the software just sees a serial data stream.
Implementing this in the emulator was pretty easy - just redirect reads/writes to the serial tape interface to a file.
I provided many of the common "tapes" that had been available from Heath as .H8T files, which you could mount and read the same way you would have read a physical tape on the H8.
Writing to tape was also supported to make/write a .H8T file.
This works well for "recreating the experience" but I never implemented actual encoding/decoding to/from audio to make it work with actual physical tapes.
https://dunfield.themindfactory.com ; "Daves Old Computers" ; SW dev addict best known:
ImageDisk: rd/wr ANY floppy PChw can ; Micro-C: compiler for DOS+ManySmallCPU ; DDLINK: simple/small filetransfer(w/o netSW)via Lan/Lpt/Com