Nyquist voice inversion script

Hi

I recently found a voice inversion scramble script, but this is written in Perl, I want to know if someone can help me to rewrite this code to Nyquist, I leave below the Perl script and the website with more information

$fs = 48000; # sample rate
$fc = 3729;  # carrier frequency
$filter = " sinc -$fc"; # optional LP filter
 
$fc = freq($fc);
 
open(IN, "sox scrambled.wav -c 1 -b 16 -e signed -t .raw -|");
open(OUT,"|sox -r $fs -c 1 -b 16 -e signed -t .raw - descrambled.wav".
         $filter);
 
while (not eof IN) {
 
  $acc += $fc;
  $acc -= 65536 if ($acc > 32767);
 
  read(IN,$a,2);
  print OUT pack("s",unpack("s",$a) * sin($acc/32768*3.141592653589793));
}

sub freq { int(.5 + $_[0] * 65536 / $fs); }

http://www.windytan.com/2013/05/descrambling-voice-inversion.html

Thanks

It’s not easy to do in Nyquist.
That script is only using Python to tell SoX what to do. SoX is an advance command line audio editor and processor - a bit like a command line version of Audacity. Nyquist in Audacity is not able to access external libraries, so it can’t use SoX, which means that to accomplish the task in Nyquist you would need to reproduce the processing that SoX is doing in Nyquist, and that is not easy.

More information about SoX here: http://sox.sourceforge.net/

So, Isn’t there a way to do a frequency inversion in Audacity?

Yes, you would do it with Nyquist, but it’s not an easy project.

Below is a link to the “Nyquist FFT and Inverse FFT Tutorial” from the Nyquist documentation.
To do frequency inversion, take the FFT of the sound. For each FFT window, “reverse” the FFT array, then apply an inverse FFT.
When you “reverse” the FFT array, remember that apart from the first and last bins you are dealing with pairs of values and the pairs need to remain in order, so:
r0 i0, r1 i1, r2 i2 … rn in
becomes:
rn in … r2 i2, r1 i1, r0 i0.

The tutorial: http://easyspacepro.com/nyquist_docs/demos/fft_tutorial.htm

On 11KHz audio, inverting the spectrum does not render voice totally scrambled …



Maybe totally incomprehensible on 22kHz audio, as most of the important frequencies will become almost ultrasonic when inverted.

How did you do the spectrum inversion in Spear

Select all, then “frequency flip” in the Transform menu …
SPEAR , Transform Menu , Frequency Flip.png
On 22kHz , when inverted, the frequencies most important to comprehend voice are inaudibly high-pitched …
Dubya , before-after inverted-spectrum 22kHz.png