Type Sound

A keystroke with a soft thock and random pitch, for text inputs.

Preview

"use client";

import { useSound } from "@/lib/sound";
import { typeSound } from "@/lib/sounds/type";

export function TypeSoundUsage() {
  const play = useSound(typeSound);
  return (
    <input
      aria-label="Message"
      placeholder="Type a message"
      // One keystroke sound per printable key, Space and Backspace.
      onKeyDown={(event) => {
        if (event.key.length === 1 || event.key === "Backspace") play();
      }}
      className="h-9 w-64 rounded-full border border-border bg-card px-4 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"
    />
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/type-sound

API Reference

sound.play(options)

volume?
number

0 to 1, multiplied with the SoundProvider volume.

Default1
pitch?
number

Pitch multiplier; 1 is the designed pitch.

Default1

useSound(sound, options)

enabled?
boolean

False makes play do nothing, for a component's sound prop.

Defaulttrue
volume?
number

0 to 1 for this sound, on top of the provider volume.

Default1

Updated