Skip to content

Commit abe6f19

Browse files
committed
Added new example
-Added a new example file that converts a .doc file to a .txt file and then generates an mp3 based on the .txt file using a text-to-speech Robot. -Added an example .doc file to use (examples/fixtures/document.doc). -Added a comment to image_resize.py explaining what that file does.
1 parent f6ad10a commit abe6f19

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

examples/file_to_tts.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
### A simple Transloadit assembly that converts a .doc file to a .txt file. It then generates an mp3 based on the .txt file using a text-to-speech Robot.
3+
4+
'''
5+
Template:
6+
7+
{
8+
"steps": {
9+
":original": {
10+
"robot": "/upload/handle"
11+
},
12+
"convert": {
13+
"use": ":original",
14+
"robot": "/document/convert",
15+
"format": "txt"
16+
},
17+
"speech": {
18+
"use": "convert",
19+
"robot": "/text/speak",
20+
"result": true,
21+
"provider": "gcp",
22+
"target_language": "en-US",
23+
"voice": "female-1"
24+
}
25+
}
26+
}
27+
'''
28+
29+
from transloadit import client
30+
31+
tl = client.Transloadit('TRANSLOADIT_KEY', 'TRANSLOADIT_SECRET')
32+
33+
def useTemplate(templateID, file_path='', result_name='', get_url=True, fields=''):
34+
assembly = tl.new_assembly({'template_id': templateID, 'fields': fields})
35+
36+
if file_path != '':
37+
assembly.add_file(open(file_path, 'rb'))
38+
39+
assembly_response = assembly.create(retries=5, wait=True)
40+
if get_url:
41+
assembly_url = assembly_response.data.get('results').get(result_name)[0].get('ssl_url')
42+
print(assembly_url)
43+
return assembly_url
44+
45+
useTemplate ('TEMPLATE_ID', file_path='fixtures/document.doc' ,result_name='speech', get_url=True)

examples/fixtures/document.doc

19 KB
Binary file not shown.

examples/image_resize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### A simple Transloadit assembly that changes the size of an image.
2+
13
from transloadit.client import Transloadit
24

35
client = Transloadit("TRANSLOADIT_KEY", "TRANSLOADIT_SECRET")

0 commit comments

Comments
 (0)