This repository was archived by the owner on Aug 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (40 loc) · 1.57 KB
/
Copy pathmain.py
File metadata and controls
58 lines (40 loc) · 1.57 KB
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
from TikTokLive.types.events import ShareEvent, CommentEvent
from TikTokPrinter import TikTokPrinterClient, EscposEngineGenerator, TikTokMedia
from TikTokPrinter.types.objects import VoiceText, PrinterText, SoundFile, PrinterImage
client: TikTokPrinterClient = TikTokPrinterClient(
unique_id="nothing.aly",
engine=EscposEngineGenerator.create_usb(
vendor_id=0x0416, # Vendor ID goes here
product_id=0x5011, # Product ID goes here
align="center"
)
)
@client.on("share")
async def on_share(event: ShareEvent):
"""
You can interface with the library to directly print text!
"""
client.text(f"Thank you, @{event.user.uniqueId}, for sharing the LIVE!")
# client.voice("Do some text to speech ;)")
# client.image(pil_image)
# client.send_message("Send this to the TikTok Live chat as a bot!")
# client.sound("./path/to/sound.mp3")
@client.on("comment")
async def on_comment(event: CommentEvent):
"""
If you want to send multiple printer commands in one go, the recommended way
to do it is through the queue method.
"""
client.queue(
PrinterText("-" * 20),
# Speak the comment
VoiceText(event.user.uniqueId + " said " + event.comment),
# Print the comment to printer
PrinterText(event.user.uniqueId + " -> " + event.comment),
# Play a sound
SoundFile("enchanted.wav"),
# Download their avatar and print the image
PrinterImage(await TikTokMedia.user_image(event.user, circle=False))
)
if __name__ == '__main__':
client.run()