I don’t think it can be done with Nyquist in Audacity. It would be possible in the standalone version of Nyquist, but Nyquist in Audacity restricts system access for safety and security reasons.
Well what I’m really after is the file size of the current project, but that doesn’t seem to be available anywhere?
Btw, I did find another method…
(listdir “C:/Temp”)
It returns a list of files for any dir, but not apparently the size of each file. So close.
The (byte (read-byte fp)) method works, but it takes way too long to process for large files. Using (byte (read-float fp)) is faster, but not enough faster.
I wish the file-length call was supported. Or anything with the file size, really.
Exactly. It is very slow because it has to read every byte in the file to count them one by one.
You would really need XLisp’s “system” function to call the appropriate system command from the operating system, but that is one of the few XLISP functions excluded from Nyquist.
The (file-length fp) call could do this instantly, if only it were present. I wouldn’t really want to do this as a system call – that’s kind of a last resort situation.
Sigh, it’s always the coding for the boundaries of what’s possible on a platform that takes the most effort.
I know you’re using (open <filename> :direction :input) currently, but is XLISP’s (s-read) also available in Audacity?
If so, you could read the file in with (s-read fname), then (immediately) query the loaded duration from the global result variable with (snd-read-dur *rslt*).
Might be too heavy for examining full-length audio recordings, since it seems to be intended for loading brief sound samples directly into memory. But it definitely works for determining the duration of a short .wav file, in the NyquistIDE.