hello there, i know there have been other threads depicting similar errors, however, perhaps i have something going on wrong that i cant quite understand:
here is the main function of my python code:
if __name__ == "__main__":
try:
# Read input from Node-RED (via stdin)
input_data = json.loads(sys.stdin.read())
audio_path = input_data.get('audio_path')
# Initialize detector with provided threshold or default value (0.5)
detector = RPWDetector(threshold=input_data.get('threshold', 0.5))
# Process audio file
if audio_path:
# Resolve relative paths if needed
if not os.path.isabs(audio_path):
script_dir = os.path.dirname(os.path.abspath(__file__))
audio_path = os.path.join(script_dir, audio_path)
# Check if file exists
if not os.path.exists(audio_path):
print(json.dumps({
'status': 'error',
'message': f'Audio file not found: {audio_path}'
}))
sys.exit(1) # Return non-zero exit code for error
result = detector.predict_class(audio_path)
if result['status'] == 'success':
# Output classification and probability in required format for Node-RED stdout
print(json.dumps({
'classification': result['classification'],
'probability': result['probability']
}))
sys.exit(0) # Return zero exit code for success
else:
print(json.dumps(result))
sys.exit(1) # Return non-zero exit code for error
else:
print(json.dumps({
'status': 'error',
'message': 'No audio path provided'
}))
sys.exit(1) # Return non-zero exit code for error
except Exception as e:
print(json.dumps({
'status': 'error',
'message': str(e)
}))
sys.exit(1) # Return non-zero exit code for error
my inject node
and my exec node calling the file.
now, when i pass this, nothing happens. it just shows a pid with a random number that changes every time i inject and nothing happens.
what ive tried:
using the json node to convert to string
putting "echo $payload | predict.py" and appending so it replaces the payload.
infact, directly inputting echo {"audio_path": "clean_1.wav"} | python predict.py
in the exec node works and i do get an output on stdout.
but i cant for the life of me manage to input it from outside the function