An open API service indexing awesome lists of open source software.

https://github.com/chuikoffru/qwik-media-recorder

Qwik hook for recording audio from microphone
https://github.com/chuikoffru/qwik-media-recorder

hooks media-recorder microphone qwik

Last synced: about 2 months ago
JSON representation

Qwik hook for recording audio from microphone

Awesome Lists containing this project

README

        

# Qwik Media Recorder

This is a simple media recorder hook for Qwik application.
It allows users to record audio from their device's microphone.

Also, it displays a recording indicator and provides a simple UI to stop/pause recording.

[![Publish to NPM](https://github.com/chuikoffru/qwik-media-recorder/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/chuikoffru/qwik-media-recorder/actions/workflows/npm-publish.yml)

## How to use it?

```
export default component$(() => {
const {
startRecording,
stopRecording,
pauseRecording,
resumeRecording,
statusRecording,
getPreview,
clearRecording,
audioBlob,
formattedDuration,
audioUrl,
} = useMediaRecorder();

const { play, isPlaying, stop, load } = useSound(audioUrl.value);

useVisibleTask$(({ track, cleanup }) => {
track(() => audioBlob.value);

console.log("audioBlob :>> ", audioBlob.value);

});

const preview = $(async () => {
if (isPlaying.value) {
stop();
return;
}
const blob = await getPreview();
const url = URL.createObjectURL(blob);
load(url);
play();
});

return (


{statusRecording.value === "ready" ? (
Start
) : statusRecording.value === "paused" ? (
Resume
) : (
Pause
)}


{formattedDuration.value}{" "}

{isPlaying.value ? "Pause" : "Play"}

{statusRecording.value === "ready" && audioUrl.value ? (
Reset
) : (

Stop

)}


);
});
```

# useSound() hook for Qwik

This hook just play a sound from audiofile.

```
import { component$ } from "@builder.io/qwik";
import { useSound } from "qwik-media-recorder";
import sound from "../assets/sound.mp3";

export const App = component$(() => {
const { play, stop, isPlaying, time, undo, redo, seek, duration } = useSound(sound);

return (
Play
);
});

```

# Transcript voice to text (SpeechRecognition)
```
export default component$(() => {
const {
startRecording,
stopRecording,
statusRecording,
transcript,
formattedDuration,
analyser
} = useMediaRecorder({ enableAnalyser: true, transcipt: { enable: true }});

useVisibleTask$(({ track }) => {
const text = track(() => transcript.value);
console.log("text :>> ", text);
});

return (


{transcript.value}


);
});
```