How to properly use play_success_sound and play_fail_sound in BarcodeScanner?

Hi all,

I’m trying to use the optional sound settings in the BarcodeScanner class of ERPNext, as mentioned in the code comment:

// optional sound name to play when scan either fails or passes.
// see https://frappeframework.com/docs/v14/user/en/python-api/hooks#sounds
this.success_sound = opts.play_success_sound;
this.fail_sound = opts.play_fail_sound;

I would like to activate these sounds during barcode scanning (e.g. in Pick List or Stock Entry), so that:

  • :white_check_mark: a sound like "submit" is played on successful scans
  • :x: a sound like "error" is played when the item is not found

However, most doctypes initialize BarcodeScanner internally, and I’m not sure how or where to pass these options (play_success_sound, play_fail_sound) during that process.

:point_right: My question is:

  • How can I activate these sounds via Custom Script or config, without fully reinitializing the BarcodeScanner?
  • Is there a recommended way to inject these options globally or after scanner init?

Hi @maydo7777
Kindly review this post — it may be helpful to you.

Thank You!

Thanks for the explanation on how to add new sounds via hooks.py – that part is clear and already working.

However, my original question is more specific:

:point_right: How do I actually activate the play_success_sound and play_fail_sound options for the barcode scanner, e.g. in Pick List or Stock Entry?

I can see in the BarcodeScanner class that these options are supported:

this.success_sound = opts.play_success_sound;
this.fail_sound = opts.play_fail_sound;

…and that the methods play_success_sound() and play_fail_sound() are called inside process_scan().

But most doctypes (like Pick List) initialize the scanner internally, and there is no documented way to pass those options into the constructor from a Custom Script.

frappe.ui.form.on('Pick List', {
    onload: function(frm) {
        if (frm.barcode_scanner) {
            frm.barcode_scanner.success_sound = "submit"; 
            frm.barcode_scanner.fail_sound = "error"; 
        }
    }
});

this is not working, normally it should work ?