Updated:

1. Give a horn with a sound (Java)

/give @s minecraft:goat_horn[instrument="minecraft:ponder_goat_horn"]

On 1.20.4 and older write {instrument:"…"} instead of [ ]. See the give command.

2. The eight sounds

Java IDBedrock data value
minecraft:ponder_goat_horn0
minecraft:sing_goat_horn1
minecraft:seek_goat_horn2
minecraft:feel_goat_horn3
minecraft:admire_goat_horn4
minecraft:call_goat_horn5
minecraft:yearn_goat_horn6
minecraft:dream_goat_horn7

The first four come from regular goats, the last four from screaming goats.

3. Bedrock

/give @s goat_horn 1 5

The data value picks the sound; 5 is call.

4. Play the sound without a horn (Java)

/execute as @a at @s run playsound minecraft:item.goat_horn.sound.5 master @s ~ ~ ~ 1 1

Sounds 0 to 7 follow the table order. Great as a start signal; see the playsound command and the countdown command.

5. Give a named horn (Java)

/give @s minecraft:goat_horn[instrument="minecraft:call_goat_horn",custom_name={"text":"Rally Horn","color":"gold","italic":false}]

This is the 1.21.5+ form. On 1.20.5 to 1.21.4, write the name as a JSON string inside single quotes. See item name colors.

6. Buff nearby players when a horn is blown (Java)

/scoreboard objectives add horn minecraft.used:minecraft.goat_horn
# Repeating command block
execute as @a[scores={horn=1..}] at @s run effect give @a[distance=..16] minecraft:speed 10 1
# Chain command block
scoreboard players reset @a[scores={horn=1..}] horn

The minecraft.used statistic counts horn uses. Everyone within 16 blocks of the player gets Speed II for 10 seconds. Swap the effect using the effect command guide, or see right-click detection for other items.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.