Skip to content

Commit 7c395f6

Browse files
committed
updated sdk with service_provider
1 parent 545a732 commit 7c395f6

File tree

8 files changed

+102
-121
lines changed

8 files changed

+102
-121
lines changed

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1-
# slashml-python-client
1+
# SLASHML Python client
22

3-
to be updated to guide users
3+
This is a Python client for SLASHML. It lets you run transcription jobs from your Python code or Jupyter notebook.
4+
5+
Grab your token from [https://www.slashml.com/dashboard/](>settings> new api key) and authenticate by setting it as an environment variable (or when you initialize the service, see examples):
6+
```
7+
export SLASHML_API_KEY=[token]
8+
```
9+
10+
-- update from this part, include examples, sign up, token, service providers, type of servies, benchmarking, link to pricing, Tutorial examples/examples
11+
12+
13+
SDK for SlashML documentation:
14+
- methods: upload_audio, transcribe, status
15+
16+
Steps to Integrate
17+
1 - (Optional) Upload files where the data points to your audio file
18+
```
19+
# call the class
20+
speect_to_text = speechtotext.SpeechToText()
21+
file_location="path/to/your/file.mp3"
22+
# when
23+
API_KEY="SLASH_ML_API_KEY"
24+
model_choice="assembly"
25+
result_upload = speect_to_text.upload_audio(file_location,API_KEY, model_choice)
26+
print(result_upload)
27+
```
28+
Save the upload_url. You can use this url link in the rest of the calls.
29+
30+
31+
2- Submit your audio file for transcription
32+
```
33+
upload_url=upload_url # you can skip step 1 and just input the accessible link of your # file)
34+
35+
result_transcribe = speect_to_text.transcribe(upload_url,API_KEY, model_choice)
36+
37+
print(result_transcribe)
38+
```
39+
Save the id in the response object.
40+
41+
42+
3 - Check the status and get the text result of the transcription
43+
```
44+
job_id= id
45+
result_status = speect_to_text.status(job_id,API_KEY, model_choice=model_choice)
46+
47+
### get the full details of the result
48+
print(result_status)
49+
### get the text reulst only
50+
print(json.loads(result)["text"])
51+
```
52+
53+
54+
et voilà, Next steps:
55+
- pip install slashml
56+
- add SLASH_API_KEY to sys path

SDK_v1/.DS_Store

0 Bytes
Binary file not shown.
-2.11 KB
Binary file not shown.

SDK_v1/readme.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

SDK_v1/speechtotext.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import requests
33
import os
44
from pathlib import Path
5+
import json
56

67
class SpeechToText:
7-
# TODO: make sure this is dynamic
8+
89
SLASHML_BASE_URL = 'https://api.slashml.com/speech-to-text/v1'
910
SLASHML_UPLOAD_URL = SLASHML_BASE_URL+'/upload/'
1011
SLASHML_TRANSCRIPT_URL = SLASHML_BASE_URL+'/transcribe/'
@@ -13,46 +14,42 @@ class SpeechToText:
1314

1415
HEADERS:dict = {}
1516
## add the api key to sys path envs
16-
def __init__(self) -> None:
17-
self.HEADERS = {'authorization': os.environ.get('SLASHML_API_KEY')}
17+
def __init__(self,SLASHML_API_KEY) -> None:
18+
self.HEADERS = {'authorization': os.environ.get('SLASHML_API_KEY')},
19+
self.API_KEY=SLASHML_API_KEY
1820

19-
def upload_audio(self, file_location:str, API_KEY: str, model_choice: str ):
20-
# here we can also add the service? assemblyai, aws, gcp?
21+
def upload_audio(self, file_location:str):
2122

22-
token="Token {0}".format(API_KEY)
23+
token="Token {0}".format(self.API_KEY)
2324
headers = {'authorization': token}
24-
payload = { 'model':model_choice }
25+
2526
files=[
2627
('audio',('test_audio.mp3',open(file_location,'rb'),'audio/mpeg'))
2728
]
28-
#import pdb
29-
#pdb.set_trace()
3029
response = requests.post(self.SLASHML_UPLOAD_URL,
31-
headers=headers,
32-
data=payload,files=files)
33-
return response.text
30+
headers=headers,files=files)
31+
32+
return json.loads(response.text)["upload_url"]
33+
34+
def transcribe(self,upload_url:str, service_provider: str ):
3435

35-
def transcribe(self,upload_url:str, API_KEY: str, model_choice: str ):
36-
# here we can add more model params
3736
transcript_request = {'audio_url': upload_url}
38-
token="Token {0}".format(API_KEY)
37+
token="Token {0}".format(self.API_KEY)
3938
headers = {'authorization': token}
4039
payload = {
4140
"uploaded_audio_url": upload_url,
42-
"model": model_choice
41+
"service_provider": service_provider
4342
}
44-
4543
response = requests.post(self.SLASHML_TRANSCRIPT_URL, headers=headers, data=payload)
46-
return response.text
44+
return json.loads(response.text)["id"]
4745

48-
def status(self,job_id:str, API_KEY: str, model_choice: str ):
49-
token="Token {0}".format(API_KEY)
46+
def status(self,job_id:str, service_provider: str ):
47+
token="Token {0}".format(self.API_KEY)
5048
headers = {'authorization': token}
5149
payload = {
52-
"model": model_choice
50+
"service_provider": service_provider
5351
}
54-
#import pdb
55-
# pdb.set_trace()
52+
5653
response = requests.get(self.SLASHML_TRANSCRIPT_STATUS_URL(job_id) , headers=headers, data=payload)
57-
return response.text
54+
return json.loads(response.text)
5855

SDK_v1/test_speechtotext.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

SDK_v1/test_speechtotext_1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import speechtotext
2+
3+
#initialize SLASHML
4+
API_KEY="1bd15e1c161ff6d4db2ea1d661d7468b4fa61ca9"
5+
speect_to_text = speechtotext.SpeechToText(API_KEY)
6+
# optional local file to upload, if not an accessible url
7+
file_location="/Users/JJneid/Desktop/SlashMl/s2t_experiments/api_tests/test_audio_1.mp3"
8+
9+
######################################################
10+
# If your audio files aren't accessible via a URL already, you can upload your audio file using this API
11+
upload_url= speect_to_text.upload_audio(file_location)
12+
13+
# choose your service provider: "asemblyai", "aws", "whisper"
14+
service_provider="assembly"
15+
# transcribe
16+
transcribe_id= speect_to_text.transcribe(upload_url,service_provider)
17+
# get the status, the result will be out after the job is done, so we wait a bit :)
18+
status=speect_to_text.status(transcribe_id,service_provider=service_provider)
19+
20+
# get the text result
21+
## assembly: status["text"]
22+
## whisper: status["transcription_data"]["transcription"]
23+
## aws: retreive result from json file link
24+
25+
print(status["text"])
26+

0 commit comments

Comments
 (0)