-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from plivo/VT-8397
Python SDK for transcription APIs
- Loading branch information
Showing
11 changed files
with
165 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Recording class - along with its list class | ||
""" | ||
|
||
from plivo.base import (ListResponseObject, PlivoResource, | ||
PlivoResourceInterface) | ||
from plivo.resources.accounts import Subaccount | ||
from plivo.utils import is_valid_time_comparison, to_param_dict | ||
from plivo.utils.validators import * | ||
|
||
|
||
class Transcription(PlivoResource): | ||
_name = 'Transcription' | ||
_identifier_string = 'transcription_id' | ||
|
||
def get_transcription(self): | ||
return self.client.transcriptions.get_transcription(self.id, **to_param_dict(self.get_transcription(), locals())) | ||
|
||
def create_transcription(self): | ||
return self.client.transcriptions.create_transcription(self.id, **to_param_dict(self.create_transcription(), locals())) | ||
|
||
def delete_transcription(self): | ||
return self.client.transcriptions.delete_transcription(self.id, **to_param_dict(self.delete_transcription(), locals())) | ||
|
||
|
||
class Transcriptions(PlivoResourceInterface): | ||
_resource_type = Transcription | ||
|
||
@validate_args(transcription_id=[of_type(six.text_type)] | ||
) | ||
def get_transcription(self, transcription_id, type=None): | ||
if not type: | ||
return self.client.request( | ||
'GET', ('Transcription', transcription_id), is_voice_request=True) | ||
else: | ||
return self.client.request( | ||
'GET', ('Transcription', transcription_id), to_param_dict(self.get_transcription, locals()), is_voice_request=True) | ||
|
||
def create_transcription(self, recording_id, transcription_callback_url=None): | ||
return self.client.request( | ||
'POST', ('Transcription', recording_id), to_param_dict(self.create_transcription, locals()), is_voice_request=True) | ||
|
||
def delete_transcription(self, transcription_id): | ||
return self.client.request( | ||
'DELETE', ('Transcription', transcription_id), is_voice_request=True) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
__version__ = '4.56.2' | ||
__version__ = '4.57.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"api_id": "c9db3f38-55e8-4d97-93b2-1ece5a342528", | ||
"message": "transcription in progress" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"api_id": "47ab0f0d-a7db-4f56-8200-6555cd3194e8", | ||
"message": "request accepted" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"api_id": "f83b30a3-228c-4676-813e-985fcdf61201", | ||
"cost": 0.05, | ||
"rate": 0.05, | ||
"recording_duration_ms": 22780, | ||
"recording_start_ms": 1729761222174, | ||
"status": "success", | ||
"transcription": "\nSpeaker 0: Scan just to be safe. If you notice any error messages, please let me know immediately. They can help us diagnose the issue better. If it continues to freeze, we might need to look into your system performance. I can guide you through checking your task manager if that helps.\n\nSometimes, background processes can use up a lot of resources. I under" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from datetime import datetime | ||
|
||
import plivo | ||
from tests.base import PlivoResourceTestCase | ||
from tests.decorators import with_response | ||
|
||
|
||
class TranscriptionTest(PlivoResourceTestCase): | ||
@with_response(200) | ||
def test_get(self): | ||
|
||
transcription = self.client.transcriptions.get_transcription('e12d05fe-6979-485c-83dc-9276114dba3b') | ||
|
||
self.assertResponseMatches(transcription) | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Transcription/e12d05fe-6979-485c-83dc-9276114dba3b/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('GET', self.client.current_request.method) | ||
|
||
self.assertEqual('\nSpeaker 0: Scan just to be safe. If you notice any error messages, please let me know immediately. They can help us diagnose the issue better. If it continues to freeze, we might need to look into your system performance. I can guide you through checking your task manager if that helps.\n\nSometimes, background processes can use up a lot of resources. I under', transcription.transcription) | ||
|
||
@with_response(201) | ||
def test_create(self): | ||
self.client.transcriptions.create_transcription( | ||
recording_id='8605287e-1e1a-4341-8235-23574357d6f1') | ||
|
||
# self.assertResponseMatches(transcription) | ||
|
||
# Verifying the endpoint hit | ||
# self.assertUrlEqual( | ||
# self.get_voice_url('Transcription', '8605287e-1e1a-4341-8235-23574357d6f1'), self.client.current_request.url) | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Transcription/8605287e-1e1a-4341-8235-23574357d6f1/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('POST', self.client.current_request.method) | ||
|
||
# self.assertEqual('transcription in progress',transcription.message) | ||
|
||
@with_response(202) | ||
def test_delete(self): | ||
transcription = self.client.transcriptions.delete_transcription( | ||
'8605287e-1e1a-4341-8235-23574357d6f1') | ||
|
||
self.assertResponseMatches(transcription) | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Transcription/8605287e-1e1a-4341-8235-23574357d6f1/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('DELETE', self.client.current_request.method) | ||
|
||
self.assertEqual('request accepted', transcription.message) |