Replace stereo track with the left channel using Nyquist not the interface of Audacity

I have a stereo track and I want to replace it with track 0 (the left channel). That is, in the end, I want the stereo track to be replaced with a mono track, which contains the left channel of the original stereo track.

I have the following code:
(aref *track* 0)

I selected the whole stereo track, but it’s not replaced with track 0. I’m using Audacity 3.7.0. The debug button shows me no errors.

What am I missing, please?

I know how to do it using Audacity’s interface, but I want to do it using Nyquist.

Thank you.

I don’t know about the “code”…

Click the 3 dots to the left of the waveform and select Split Stereo to Mono.

Then click the little ‘X’ (again to the left of the waveforms) to delete the right channel (bottom waveform).

Without being rude, I specifically mentioned in my post “I know how to do it using Audacity’s interface, but I want to do it using Nyquist.”

Nyquist can give you just the left channel of the selected audio, but it cannot directly change the type of audio track from a stereo track to a mono track. As you wrote. (aref *track* 0) returns just the left channel of the selected stereo track, but it gets returned back into the same (stereo) track, so you end up with a stereo track containing the original left channel in both of the new channels.

To change the kind of audio track from stereo to mono requires an Audacity command. Typically you would do this from the track’s context menu, but you can also use AUD-DO or AUD-DO-COMMAND to send commands to Audacity. (See this section of the manual: Nyquist-Macros - Audacity Manual)

Unfortunately the track context menu commands are not available as Macro commands. The workaround is to pan the track left, then mix down to mono:

The double quotes at the end is required so that Audacity knows that it is not expecting to receive data from Nyquist:

(aud-do-command "PanLeft")
(aud-do-command "Stereo to Mono")
""

An important limitation of “Nyquist Macros” is that you cannot mix running Macro command in a Nyquist plug-in, with running normal Nyquist commands to modify the project. A Nyquist plug-in can do one or the other, but not both within the same Nyquist script.

Steve, thank you so much for your answer and particularly for the sentence above.

Is there any Nyquist command to delete the whole track and to paste the left channel only, as a workaround?

The best workaround is the one I described in my previous post.

Yes you can delete a track (should be able to) using a Nyquist Macro command:

(aud-do-command "TrackClose")

However, on my machine, using Audacity 3.7.1, Audacity crashes after deleting the track.
(Crash when deleting track with Nyquist Macro · Issue #8364 · audacity/audacity · GitHub)

Also. you cannot paste stereo audio into a mono track, so you would still need to pan and mix to mono before copying.

The best workaround is the one I described in my previous post.

I deeply appreciate when someone with your vast knowledge takes the time to explain a solution. While I don’t doubt your answer for a second, I was also curious about how the code below would work:

(setq left-channel-sound (aref *track* 0))
(aud-do-command "TrackClose")
(aud-do-command "NewMonoTrack")
(setq *track* (snd-seq left-channel-sound))

And yes, it crashed on my Windows machine as well:
`Crash reason: EXCEPTION_ACCESS_VIOLATION_WRITE``