Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4615

Graphics, sound and multimedia • How do I fix this Python code?

$
0
0
I am making a audio recorder with a Raspberry Pi 0 W 2 and I have some python code. The problem is that they are 2 separate projects. (1 for playing and 1 for pausing.) How can I make it 1 project? When I run the code, it starts recording, but when I stop the code, it still runs. My goal is when I run the code, it records, and when I stop running the code it stops recording. I am using the Audacity script-mod-pipe. What should I do?
Here is my code:

Code:

import sysimport osimport sysif sys.platform == 'win32':    print("pipe-test.py, running on windows")    TONAME = '\\\\.\\pipe\\ToSrvPipe'    FROMNAME = '\\\\.\\pipe\\FromSrvPipe'    EOL = '\r\n\0'else:    print("pipe-test.py, running on linux or mac")    TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())    FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())    EOL = '\n'print("Write to  \"" + TONAME +"\"")if not os.path.exists(TONAME):    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")    sys.exit()print("Read from \"" + FROMNAME +"\"")if not os.path.exists(FROMNAME):    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")    sys.exit()print("-- Both pipes exist.  This is a good thing.")TOFILE = open(TONAME, 'w')print("-- File to which to write has been opened")FROMFILE = open(FROMNAME, 'rt')print("-- File from which to read has now been opened also\r\n")def send_command(command):    """Send a single command."""    print("Send: >>> \n"+command)    TOFILE.write(command + EOL)    TOFILE.flush()#record command  \/send_command("Record1stChoice")import sysimport osimport sysif sys.platform == 'win32':    print("pipe-test.py, running on windows")    TONAME = '\\\\.\\pipe\\ToSrvPipe'    FROMNAME = '\\\\.\\pipe\\FromSrvPipe'    EOL = '\r\n\0'else:    print("pipe-test.py, running on linux or mac")    TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())    FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())    EOL = '\n'print("Write to  \"" + TONAME +"\"")if not os.path.exists(TONAME):    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")    sys.exit()print("Read from \"" + FROMNAME +"\"")if not os.path.exists(FROMNAME):    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")    sys.exit()print("-- Both pipes exist.  This is a good thing.")TOFILE = open(TONAME, 'w')print("-- File to which to write has been opened")FROMFILE = open(FROMNAME, 'rt')print("-- File from which to read has now been opened also\r\n")def send_command(command):    """Send a single command."""    print("Send: >>> \n"+command)    TOFILE.write(command + EOL)    TOFILE.flush()#stop command  \/send_command("Stop")
As you can see, there are 2 scripts, how can I make it only 1?

Statistics: Posted by Henrik Gill — Sun Feb 25, 2024 1:34 pm — Replies 0 — Views 34



Viewing all articles
Browse latest Browse all 4615

Trending Articles