Convert Label text to LRC file

Help for Audacity on Windows.
Forum rules
ImageThis forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".


Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Sun Mar 01, 2020 12:12 pm

I modified the code and write the output to a binary file:

Code: Select all

 write_json = open('labels.json', 'wb')
*snip*

   while (last != b'\n' or line != b'\n'):
        last = line
        line = read_pipe.read(1)
        print(line.hex(), end=' ')
        write_json.write( line)
It still shows me the wxwidgets path:

Code: Select all

0.452789	0.452789	hello
1.044898	1.044898	小苹果
Image

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert Label text to LRC file

Post by steve » Sun Mar 01, 2020 2:00 pm

This will return the byte values (This version is for Linux and will need adapting for Windows)

Code: Select all

import os
import sys
PIPE_BASE = '/tmp/audacity_script_pipe.'
WRITE_NAME = PIPE_BASE + 'to.' + str(os.getuid())
READ_NAME = PIPE_BASE + 'from.' + str(os.getuid())
EOL = '\n'
write_pipe = open(WRITE_NAME, 'w')
read_pipe = open(READ_NAME, 'rb')

def send_command(command):
    """Send a single command."""
    print("Send: >>> \n"+command)
    write_pipe.write(command + EOL)
    write_pipe.flush()

def get_response():
    """Return the command response."""
    eolCount = 0
    bytes = bytearray([])
    while eolCount < 2:
        byte = read_pipe.read(1)
        bytes += byte
        if byte == b'\n' :
            eolCount +=1
        else:
            eolCount = 0
    print(bytes.hex())

send_command("GetInfo: Type=Labels")
get_response()

The problem though is that the returned bytes may not all be valid UTF-8, so I don't know how you would decoded it.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Mar 03, 2020 2:59 am

Following pipe_test.py code adapted:

Code: Select all

WRITE_NAME = '\\\\.\\pipe\\ToSrvPipe'
READ_NAME = '\\\\.\\pipe\\FromSrvPipe'
EOL = '\r\n\0'
This is my output. You still can see 4 zero bytes followed by the path "633a5c777877696467...", just like the last time I tried.

Code: Select all

C:\tmp>python get-labels.py
Send: >>>
GetInfo: Type=Labels
5b200a20205b20312c0a202020205b200a2020202020205b20302e3837303734382c20302e383730
3734382c202268656c6c6f22205d2c0a00000000633a5c7778776964676574732d332e312e315c69
6e636c7564655c77785c7374727661724261746368436f6d6d616e642066696e69736865643a204f
4b0a0a

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert Label text to LRC file

Post by steve » Tue Mar 03, 2020 11:08 am

bigboss97 wrote:
Tue Mar 03, 2020 2:59 am
This is my output. You still can see 4 zero bytes followed by the path "633a5c777877696467...", just like the last time I tried.
What output do you get from two labels, each containing: 不要你
What output do you get from the "GetInfo" menu command with those labels?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Mar 03, 2020 11:33 am

steve wrote:
Tue Mar 03, 2020 11:08 am
What output do you get from two labels, each containing: 不要你
What output do you get from the "GetInfo" menu command with those labels?
Image
The arrow is pointing at the path.

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert Label text to LRC file

Post by steve » Tue Mar 03, 2020 11:38 am

I'm trying to work out where the encoding / decoding is going wrong.
I can't copy and paste digits from a screenshot.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Mar 03, 2020 11:47 am

Code: Select all

5b200a20205b20302c0a202020205b200a2020202020205b20302e3333363638392c20302e3333363638392c202248656c6c6f22205d2c0a00000000633a5c7778776964676574732d332e312e315c696e636c7564655c77785c7374727661724261746368436f6d6d616e642066696e69736865643a204f4b0a0a

Code: Select all


[ 
  [ 0,
    [ 
      [ 0.336689, 0.336689, "Hello" ],
      [ 2.15946, 2.15946, "小苹果" ] ] ] ]
      

bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Mar 03, 2020 11:51 am

bigboss97 wrote:
Sun Mar 01, 2020 12:12 pm

Code: Select all

0.452789	0.452789	hello
1.044898	1.044898	小苹果
Image
Just like my old post (above), there are 4x zero bytes then followed by a path.

steve
Site Admin
Posts: 81264
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Convert Label text to LRC file

Post by steve » Tue Mar 03, 2020 4:45 pm

You're getting less on Windows than I do on Linux. Your version appears to be completely choking on the Unicode characters.

For the current version of Audacity, it appears that the script pipe module does not support Unicode at all on Windows. I've written to the developers about this, but I'm not hopeful of Unicode support being added any time soon, unless the problem was just an oversight that can be easily fixed.

I'll write back if I get more information. Sorry I couldn't be more help.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bigboss97
Posts: 45
Joined: Sat Feb 08, 2020 6:28 am
Operating System: Windows 10

Re: Convert Label text to LRC file

Post by bigboss97 » Tue Mar 03, 2020 9:28 pm

Thank you for your time 👍

Post Reply