-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
audio.go
99 lines (82 loc) · 2.66 KB
/
audio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package message
import (
"context"
"time"
"github.com/gotd/td/tg"
)
// Audio creates new AudioDocumentBuilder to create audio attachment.
func (u *UploadedDocumentBuilder) Audio() *AudioDocumentBuilder {
b := u
if u.doc.MimeType == "" {
b = u.MIME(DefaultAudioMIME)
}
return &AudioDocumentBuilder{
doc: b,
attr: tg.DocumentAttributeAudio{},
}
}
// Voice creates new AudioDocumentBuilder to create voice attachment.
func (u *UploadedDocumentBuilder) Voice() *AudioDocumentBuilder {
return u.MIME(DefaultVoiceMIME).Audio().Voice()
}
// AudioDocumentBuilder is a Audio media option.
type AudioDocumentBuilder struct {
doc *UploadedDocumentBuilder
attr tg.DocumentAttributeAudio
}
// Voice sets flag to mark this audio as voice message.
func (u *AudioDocumentBuilder) Voice() *AudioDocumentBuilder {
u.attr.Voice = true
return u
}
// Duration sets duration of audio file.
func (u *AudioDocumentBuilder) Duration(duration time.Duration) *AudioDocumentBuilder {
return u.DurationSeconds(int(duration.Seconds()))
}
// DurationSeconds sets duration in seconds.
func (u *AudioDocumentBuilder) DurationSeconds(duration int) *AudioDocumentBuilder {
u.attr.Duration = duration
return u
}
// Title sets name of song.
func (u *AudioDocumentBuilder) Title(title string) *AudioDocumentBuilder {
u.attr.Title = title
return u
}
// Performer sets performer.
func (u *AudioDocumentBuilder) Performer(performer string) *AudioDocumentBuilder {
u.attr.Performer = performer
return u
}
// Waveform sets waveform representation of the voice message.
func (u *AudioDocumentBuilder) Waveform(waveform []byte) *AudioDocumentBuilder {
u.attr.Waveform = waveform
return u
}
// apply implements MediaOption.
func (u *AudioDocumentBuilder) apply(ctx context.Context, b *multiMediaBuilder) error {
return u.doc.Attributes(&u.attr).apply(ctx, b)
}
// applyMulti implements MultiMediaOption.
func (u *AudioDocumentBuilder) applyMulti(ctx context.Context, b *multiMediaBuilder) error {
return u.doc.Attributes(&u.attr).applyMulti(ctx, b)
}
// Audio adds audio attachment.
func Audio(file tg.InputFileClass, caption ...StyledTextOption) *AudioDocumentBuilder {
return UploadedDocument(file, caption...).Audio()
}
// Voice adds voice attachment.
func Voice(file tg.InputFileClass) *AudioDocumentBuilder {
return UploadedDocument(file).Voice()
}
// Audio sends audio file.
func (b *Builder) Audio(
ctx context.Context,
file tg.InputFileClass, caption ...StyledTextOption,
) (tg.UpdatesClass, error) {
return b.Media(ctx, Audio(file, caption...))
}
// Voice sends voice message.
func (b *Builder) Voice(ctx context.Context, file tg.InputFileClass) (tg.UpdatesClass, error) {
return b.Media(ctx, Voice(file))
}