# Device sound and utilities

> The rest of the Device facade — beep, vibrate, clipboard, wireless radios, TTS/STT, platform.

Source: https://crossfly.dev/docs/data-and-services/device-sound-and-misc — CrossFly documentation. Full docs as one file: https://crossfly.dev/llms-full.txt

# Device sound and utilities

The **`Device`** facade gathers small, portable features. Everything static.

## Feedback and system
```java
Device.beep();              // system beep
Device.vibrate(200);        // vibrates 200 ms
Device.sleep(500);          // pauses the current thread 500 ms
int livre = Device.getFreeMemory();
Device.show("https://exemplo.com");   // opens a URL/resource in the OS's external app
```

## Clipboard
```java
Device.clipboardCopy("texto");
String colado = Device.clipboardPaste();
```

## Identity and platform
```java
if (Device.platform.isMobile()) { ... }     // ANDROID/IPHONE/IPAD
if (Device.platform.isDesktop()) { ... }    // WINDOWS/LINUX/MACOS
if (Device.platform.isIOS()) { ... }        // IPHONE/IPAD
String base = Device.homeFolder;            // app base directory
```
`Platform`: `JAVA` · `WINDOWS` · `LINUX` · `IPHONE` · `ANDROID` · `IPAD` · `MACOS`.

## Wireless radios
```java
WirelessState wifi = Device.getWirelessState(WirelessType.WIFI);   // UNSUPPORTED/DISABLED/ENABLED
Device.enableWireless(WirelessType.BLUETOOTH, true);
```
`WirelessType`: `WIFI` · `PHONE` · `BLUETOOTH`.

## Voice — TTS and STT
```java
Device.textToVoice("Olá, mundo");   // speaks the text (TTS)

Device.voiceToText(new Device.VoiceToTextListener() {   // speech recognition (STT)
   public void onStart() {}
   public void onFinish() {}
   public void onResult(String texto) { Component.onUI(() -> campo.text(texto)); }
   public void onError(int code, String msg) { Component.onUI(() -> Hint.show(msg, 2000)); }
});
```
> STT callbacks arrive **off the paint thread** → come back with `Component.onUI(...)`.

## ⚠️ Migration notes
- `Sound.*` and `RadioState` **were absorbed into `Device`** — `Sound.tone`/`play` **no longer exist**.
- On **Web/TeaVM**, much of this is a *stub* (vibration, radios, voice) — handle the Web target.

## Best practices
- Voice/radio callbacks come back to the UI with `onUI(...)`.
- Check `WirelessState.UNSUPPORTED` before assuming a radio exists.

## Common mistakes
- Calling `Sound.play(...)`/`RadioState` (removed) — use `Device`.
- Touching the UI directly in the STT `onResult` without `onUI`.

## See also
- [Biometrics](/docs/data-and-services/device-biometry) · [Background work](/docs/data-and-services/background-work)
