Skip to content

Commit 0c9072f

Browse files
committed
feat: voice recording
1 parent 20daf91 commit 0c9072f

File tree

103 files changed

+2521
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2521
-551
lines changed
Loading
Loading
Loading
Loading
Loading
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
id: voice-recordings
3+
title: Voice recordings
4+
---
5+
6+
import VoiceRecordingScreenshot from "../assets/voice-recording-screenshot.png";
7+
import StartRecording from "../assets/start-voice-recording.png";
8+
import RecordingDemo from "../assets/voice-recording-demo.png";
9+
import Playback from "../assets/voice-recording-playback.png";
10+
11+
The Stream API allows you to send voice recordings as attachments. This is an example attachment:
12+
13+
```json
14+
{
15+
"type": "voiceRecording",
16+
"title": "audio_recording_2024-09-26T14:41:24.473Z.wav",
17+
"asset_url": "https://dublin.stream-io-cdn.com/...",
18+
"waveform_data": [
19+
0.03389095297537962,
20+
0.03389095297537962,
21+
0.19684165186582253 //...
22+
],
23+
"duration": 3.119,
24+
"file_size": 97964,
25+
"mime_type": "audio/wav"
26+
}
27+
```
28+
29+
## Playing voice recordings
30+
31+
The SDK can play these recordings without any additional setup:
32+
33+
<img src={VoiceRecordingScreenshot} width="500" />
34+
35+
If you'd like to use your own UI, you can provide your own template using the [custom templates service](../../services/CustomTemplatesService/#voicerecordingattachmenttemplate).
36+
37+
## Creating voice recordings
38+
39+
However, if you want to let users to create voice recordings, you have to configure the SDK with a few easy steps.
40+
41+
### Start recording button
42+
43+
The [message input](../../components/MessageInputComponent) component can optionally display the start recording button. This is how you can enable it:
44+
45+
```html
46+
<stream-message-input
47+
[displayVoiceRecordingButton]="true"
48+
></stream-message-input>
49+
```
50+
51+
This is how the input looks with the button enabled:
52+
53+
<img src={StartRecording} width="500" />
54+
55+
You can also display your own start button, the easiest way is to use the `message-input-start` or `message-input-end` attributes which will instert the element before or after the textarea element:
56+
57+
```html
58+
<stream-message-input #input [displayVoiceRecordingButton]="false">
59+
<button message-input-start (click)="input.startVoiceRecording()">
60+
Start recording
61+
</button>
62+
</stream-message-input>
63+
```
64+
65+
### Import the `VoiceRecorderModule`
66+
67+
The `VoiceRecorderModule` contains the voice recorder component, and the services needed to make a recording. You have to import it like this:
68+
69+
```typescript
70+
import { StreamChatModule, VoiceRecorderModule } from "stream-chat-angular";
71+
72+
@NgModule({
73+
declarations: [AppComponent],
74+
imports: [
75+
// other imports...
76+
StreamChatModule,
77+
VoiceRecorderModule,
78+
// ...more imports
79+
],
80+
bootstrap: [AppComponent],
81+
})
82+
export class AppModule {}
83+
```
84+
85+
### Display the voice recorder component
86+
87+
You have to provide the voice recorder template to the message input component. The SDK provides the `VoiceRecorderComponent` for this:
88+
89+
```html
90+
<stream-message-input [displayVoiceRecordingButton]="true">
91+
<ng-template voice-recorder let-service="service">
92+
<stream-voice-recorder
93+
[voiceRecorderService]="service"
94+
></stream-voice-recorder>
95+
</ng-template>
96+
</stream-message-input>
97+
```
98+
99+
The message input provides a [`VoiceRecorderService`](../../services/VoiceRecorderService) instance which is used by the two components to communicate.
100+
101+
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.
102+
103+
### Voice recorder component
104+
105+
That's it. We can now start a voice recording:
106+
107+
<img src={RecordingDemo} width="500" />
108+
109+
The recording can be paused and resumed. Once a user is finished recording they can play it back:
110+
111+
<img src={Playback} width="500" />
112+
113+
If they are not happy with the recording, they can simply discard it. Once the reacording is finalized, they can hit the send button.
114+
115+
### Sending modes
116+
117+
There are two ways to send voice recordings:
118+
119+
1. Once a recording is finalized you can immediately send a message with the recording, this is the default mode.
120+
2. Once a recording is finalized you can return to the message composer to continue editing the message.
121+
122+
This how you can change between the modes:
123+
124+
```typescript
125+
constructor(private messageInputService: MessageInputConfigService) {
126+
// Defaults to true
127+
// Set false if you want to return to the message composer after a recording was added to the message
128+
this.messageInputService.sendVoiceRecordingImmediately = true;
129+
}
130+
```
131+
132+
### Error states
133+
134+
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.
135+
136+
### Custom recording title
137+
138+
You can use your own method the generate the title of the recording using the `customGenerateRecordingTitle` field of the `AudioRecorderService`.
139+
140+
```typescript
141+
constructor(private audioRecorder: AudioRecorderService, private chatService: ChatClientService) {
142+
this.audioRecorder.customGenerateRecordingTitle = (
143+
options: MediaRecordingTitleOptions
144+
) => {
145+
const extension = options.mimeType.match(/\/([^/;]+)/)?.[1] || "";
146+
return `${
147+
this.chatService.chatClient.user?.name
148+
}-${new Date().toISOString()}.${extension}`;
149+
};
150+
}
151+
```

docusaurus/docs/Angular/components/AttachmentListComponent.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The id of the message the attachments belong to
122122

123123
#### Defined in
124124

125-
[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)
125+
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:39](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L39)
126126

127127
---
128128

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

135135
#### Defined in
136136

137-
[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)
137+
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:43](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L43)
138138

139139
---
140140

@@ -146,7 +146,7 @@ The attachments to display
146146

147147
#### Defined in
148148

149-
[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)
149+
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:47](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L47)
150150

151151
---
152152

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

159159
#### Defined in
160160

161-
[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)
161+
[projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts:51](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts#L51)
162162

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

docusaurus/docs/Angular/components/AttachmentPreviewListComponent.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ A stream that emits the current file uploads and their states
4747

4848
#### Defined in
4949

50-
[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)
50+
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:17](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L17)
5151

5252
---
5353

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

6060
#### Defined in
6161

62-
[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)
62+
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:21](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L21)
6363

6464
---
6565

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

7272
#### Defined in
7373

74-
[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)
74+
[projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts:25](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/attachment-preview-list/attachment-preview-list.component.ts#L25)
7575

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

docusaurus/docs/Angular/components/AutocompleteTextareaComponent.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TextareaInterface.value
5151

5252
#### Defined in
5353

54-
[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)
54+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:49](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L49)
5555

5656
---
5757

@@ -67,7 +67,7 @@ TextareaInterface.placeholder
6767

6868
#### Defined in
6969

70-
[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)
70+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:53](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L53)
7171

7272
---
7373

@@ -83,7 +83,7 @@ TextareaInterface.areMentionsEnabled
8383

8484
#### Defined in
8585

86-
[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)
86+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:57](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L57)
8787

8888
---
8989

@@ -99,7 +99,7 @@ TextareaInterface.inputMode
9999

100100
#### Defined in
101101

102-
[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)
102+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:61](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L61)
103103

104104
---
105105

@@ -115,7 +115,7 @@ TextareaInterface.mentionScope
115115

116116
#### Defined in
117117

118-
[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)
118+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:65](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L65)
119119

120120
---
121121

@@ -131,7 +131,7 @@ TextareaInterface.autoFocus
131131

132132
#### Defined in
133133

134-
[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)
134+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:69](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L69)
135135

136136
---
137137

@@ -147,7 +147,7 @@ TextareaInterface.valueChange
147147

148148
#### Defined in
149149

150-
[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)
150+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:73](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L73)
151151

152152
---
153153

@@ -163,7 +163,7 @@ TextareaInterface.send
163163

164164
#### Defined in
165165

166-
[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)
166+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:77](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L77)
167167

168168
---
169169

@@ -179,6 +179,6 @@ TextareaInterface.userMentions
179179

180180
#### Defined in
181181

182-
[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)
182+
[projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts:81](https://github.com/GetStream/stream-chat-angular/blob/c4925a571484c046f73b9e63286a2e64380af0c6/projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.ts#L81)
183183

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

0 commit comments

Comments
 (0)