Skip to content

Commit

Permalink
feat: voice recording
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Sep 27, 2024
1 parent 20daf91 commit c4925a5
Show file tree
Hide file tree
Showing 104 changed files with 2,472 additions and 551 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docusaurus/docs/Angular/assets/voice-recorder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions docusaurus/docs/Angular/code-examples/voice-recordings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
id: voice-recordings
title: Voice recordings
---

import VoiceRecordingScreenshot from "../assets/voice-recording-screenshot.png";
import StartRecording from "../assets/start-voice-recording.png";
import RecordingDemo from "../assets/voice-recording-demo.png";
import Playback from "../assets/voice-recording-playback.png";

The Stream API allows you to send voice recordings as attachments. This is an example attachment:

```json
{
"type": "voiceRecording",
"title": "audio_recording_2024-09-26T14:41:24.473Z.wav",
"asset_url": "https://dublin.stream-io-cdn.com/...",
"waveform_data": [
0.03389095297537962,
0.03389095297537962,
0.19684165186582253 //...
],
"duration": 3.119,
"file_size": 97964,
"mime_type": "audio/wav"
}
```

## Playing voice recordings

The SDK can play these recordings without any additional setup:

<img src={VoiceRecordingScreenshot} width="500" />

If you'd like to use your own UI, you can provide your own template using the [custom templates service](../services/CustomTemplatesService/#voicerecordingattachmenttemplate).

## Creating voice recordings

However, if you want to let users to create voice recordings, you have to configure the SDK with a few easy steps.

### Start recording button

The [message input](../../components/MessageInputComponent) component can optionally display the start recording button. This is how you can enable it:

```html
<stream-message-input
[displayVoiceRecordingButton]="true"
></stream-message-input>
```

This is how the input looks with the button enabled:

<img src={StartRecording} width="500" />

### Import the `VoiceRecorderModule`

The `VoiceRecorderModule` contains the voice recorder component, and the services needed to make a recording. You have to import it like this:

```typescript
import { StreamChatModule, VoiceRecorderModule } from "stream-chat-angular";

@NgModule({
declarations: [AppComponent],
imports: [
// other imports...
StreamChatModule,
VoiceRecorderModule,
// ...more imports
],
bootstrap: [AppComponent],
})
export class AppModule {}
```

### Display the voice recorder component

You have to provide the voice recorder template to the message input component. The SDK provides the `VoiceRecorderComponent` for this:

```html
<stream-message-input [displayVoiceRecordingButton]="true">
<ng-template voice-recorder let-service="service">
<stream-voice-recorder
[voiceRecorderService]="service"
></stream-voice-recorder>
</ng-template>
</stream-message-input>
```

The message input provides a [`VoiceRecorderService`](../../services/VoiceRecorderService) instance which is used by the two components to communicate.

If you want to use your own UI, just simply provide you own component here that uses `VoiceRecorderService` to communicate with the message input component.

### Voice recorder component

That's it. We can now start a voice recording:

<img src={RecordingDemo} width="500" />

The recording can be paused and resumed. Once a user is finished recording they can play it back:

<img src={Playback} width="500" />

If they are not happy with the recording, they can simply discard it. Once the reacording is finalized, they can hit the send button.

### Sending modes

There are two ways to send voice recordings:

1. Once a recording is finalized you can immediately send a message with the recording, this is the default mode.
2. Once a recording is finalized you can return to the message composer to continue editing the message.

This how you can change between the modes:

```typescript
constructor(private messageInputService: MessageInputConfigService) {
// Defaults to true
// Set false if you want to return to the message composer after a recording was added to the message
this.messageInputService.sendVoiceRecordingImmediately = true;
}
```

### Error states

If any time during the recording an error occurs, the recording will be stopped, and an error message will be emitted via the [`NotificationService`](../../services/NotificationService). The built-in `stream-notification-list` component will display this error message.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The id of the message the attachments belong to

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:39](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L39)
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:39](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L39)

---

Expand All @@ -134,7 +134,7 @@ The parent id of the message the attachments belong to

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:43](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L43)
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:43](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L43)

---

Expand All @@ -146,7 +146,7 @@ The attachments to display

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:47](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L47)
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:47](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L47)

---

Expand All @@ -158,6 +158,6 @@ Emits the state of the image carousel window

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:51](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L51)
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:51](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L51)

[//]: # "End of generated content"
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ A stream that emits the current file uploads and their states

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:17](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L17)
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:17](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L17)

---

Expand All @@ -59,7 +59,7 @@ An output to notify the parent component if the user tries to retry a failed upl

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:21](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L21)
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:21](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L21)

---

Expand All @@ -71,6 +71,6 @@ An output to notify the parent component if the user wants to delete a file

#### Defined in

[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:25](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L25)
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:25](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L25)

[//]: # "End of generated content"
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ TextareaInterface.value

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:49](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L49)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:49](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L49)

---

Expand All @@ -67,7 +67,7 @@ TextareaInterface.placeholder

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:53](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L53)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:53](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L53)

---

Expand All @@ -83,7 +83,7 @@ TextareaInterface.areMentionsEnabled

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:57](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L57)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:57](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L57)

---

Expand All @@ -99,7 +99,7 @@ TextareaInterface.inputMode

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:61](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L61)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:61](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L61)

---

Expand All @@ -115,7 +115,7 @@ TextareaInterface.mentionScope

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:65](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L65)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:65](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L65)

---

Expand All @@ -131,7 +131,7 @@ TextareaInterface.autoFocus

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:69](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L69)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:69](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L69)

---

Expand All @@ -147,7 +147,7 @@ TextareaInterface.valueChange

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:73](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L73)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:73](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L73)

---

Expand All @@ -163,7 +163,7 @@ TextareaInterface.send

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:77](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L77)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:77](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L77)

---

Expand All @@ -179,6 +179,6 @@ TextareaInterface.userMentions

#### Defined in

[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:81](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L81)
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:81](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L81)

[//]: # "End of generated content"
16 changes: 8 additions & 8 deletions docusaurus/docs/Angular/components/AvatarComponent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ An optional name of the image, used for fallback image or image title (if `image

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:36](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L36)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:36](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L36)

---

Expand All @@ -83,7 +83,7 @@ The URL of the image to be displayed. If the image can't be displayed the first

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:40](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L40)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:40](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L40)

---

Expand All @@ -95,7 +95,7 @@ The location the avatar will be displayed in

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:44](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L44)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:44](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L44)

---

Expand All @@ -107,7 +107,7 @@ The channel the avatar belongs to (if avatar of a channel is displayed)

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:48](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L48)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:48](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L48)

---

Expand All @@ -119,7 +119,7 @@ The user the avatar belongs to (if avatar of a user is displayed)

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:52](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L52)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:52](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L52)

---

Expand All @@ -131,7 +131,7 @@ The type of the avatar: channel if channel avatar is displayed, user if user ava

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:56](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L56)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:56](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L56)

---

Expand All @@ -143,7 +143,7 @@ If a channel avatar is displayed, and if the channel has exactly two members a g

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:60](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L60)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:60](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L60)

---

Expand All @@ -155,6 +155,6 @@ If channel/user image isn't provided the initials of the name of the channel/use

#### Defined in

[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:64](https://github.com/GetStream/stream-chat-angular/blob/502385cb9d3f2df94a8714de2a742aeb1edfb77e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L64)
[projects/stream-chat-angular/src/lib/avatar/avatar.component.ts:64](https://github.com/GetStream/stream-chat-angular/blob/b26d7dd06f6038780332fd1e138b515cf30f5d9e/projects/stream-chat-angular/src/lib/avatar/avatar.component.ts#L64)

[//]: # "End of generated content"
Loading

0 comments on commit c4925a5

Please sign in to comment.