Skip to content

Commit a604b77

Browse files
authored
SWI-2563 Add detect_language (#152)
* SWI-2563 Add `detect_language` * Update sleep for getCall * more sleep
1 parent b646033 commit a604b77

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

bandwidth/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def test_successful_create_and_get_call(self, voice_client):
222222

223223
create_response = voice_client.create_call(BW_ACCOUNT_ID, call_body)
224224
create_response_body = create_response.body
225-
time.sleep(3)
225+
time.sleep(15)
226226
get_response = voice_client.get_call(BW_ACCOUNT_ID, create_response.body.call_id)
227227
get_response_body = get_response.body
228228

bandwidth/tests/test_bxml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def test_record(self):
141141
terminating_digits="#",
142142
max_duration=90,
143143
file_format="mp3",
144+
detect_language=True,
144145
transcribe=False,
145146
transcription_available_url="https://transcribe.url.server/available",
146147
transcription_available_method="POST",
@@ -151,7 +152,7 @@ def test_record(self):
151152
fallback_password="fpass"
152153
)
153154
response.add_verb(record)
154-
expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Record tag="tag" username="user" password="pass" recordCompleteUrl="https://record.url.server/record" recordCompleteMethod="POST" recordingAvailableUrl="https://record.url.server/available" recordingAvailableMethod="GET" terminatingDigits="#" maxDuration="90" fileFormat="mp3" transcribe="false" transcriptionAvailableUrl="https://transcribe.url.server/available" transcriptionAvailableMethod="POST" silenceTimeout="90" recordCompleteFallbackUrl="https://test.com" recordCompleteFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"/></Response>'
155+
expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Record tag="tag" username="user" password="pass" recordCompleteUrl="https://record.url.server/record" recordCompleteMethod="POST" recordingAvailableUrl="https://record.url.server/available" recordingAvailableMethod="GET" terminatingDigits="#" maxDuration="90" fileFormat="mp3" detectLanguage="true" transcribe="false" transcriptionAvailableUrl="https://transcribe.url.server/available" transcriptionAvailableMethod="POST" silenceTimeout="90" recordCompleteFallbackUrl="https://test.com" recordCompleteFallbackMethod="GET" fallbackUsername="fuser" fallbackPassword="fpass"/></Response>'
155156
assert response.to_bxml() == expected_bxml
156157

157158
def test_redirect(self):
@@ -445,5 +446,3 @@ def test_stop_stream_bxml_verb(self):
445446
actual = response.to_bxml()
446447

447448
assert expected == actual
448-
449-

bandwidth/voice/bxml/verbs/record.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Record(AbstractBxmlVerb):
1717

1818
def __init__(self, tag=None, username=None, password=None, record_complete_url=None, record_complete_method=None,
1919
recording_available_url=None, recording_available_method=None, terminating_digits=None, max_duration=None,
20-
file_format=None, transcribe=None, transcription_available_url=None, transcription_available_method=None,
20+
file_format=None, detect_language=None, transcribe=None, transcription_available_url=None, transcription_available_method=None,
2121
silence_timeout=None, record_complete_fallback_url=None, record_complete_fallback_method=None,
2222
fallback_username=None, fallback_password=None):
2323
"""
@@ -33,6 +33,7 @@ def __init__(self, tag=None, username=None, password=None, record_complete_url=N
3333
:param str terminating_digits: Digits to terminate the recording
3434
:param int max_duration: Max duration to record in seconds
3535
:param str file_format: The file format to save the recording in
36+
:param bool detect_language: Indicates that the recording may not be in English, and the transcription service will need to detect the dominant language the recording is in and transcribe accordingly. Current supported languages are English, French, and Spanish.
3637
:param bool transcribe: True to transcribe the recording on completion, False otherwise
3738
:param str transcription_available_url: URL to send the transcriptionAvailable event to.
3839
:param str transcription_available_method: The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST
@@ -52,6 +53,7 @@ def __init__(self, tag=None, username=None, password=None, record_complete_url=N
5253
self.terminating_digits = terminating_digits
5354
self.max_duration = max_duration
5455
self.file_format = file_format
56+
self.detect_language = detect_language
5557
self.transcribe = transcribe
5658
self.transcription_available_url = transcription_available_url
5759
self.transcription_available_method = transcription_available_method
@@ -83,6 +85,10 @@ def to_bxml(self):
8385
root.set("maxDuration", str(self.max_duration))
8486
if self.file_format is not None:
8587
root.set("fileFormat", self.file_format)
88+
if self.detect_language is not None:
89+
#Convert True to "true", or False to "false"
90+
strn = "true" if self.detect_language else "false"
91+
root.set("detectLanguage", strn)
8692
if self.transcribe is not None:
8793
#Convert True to "true", or False to "false"
8894
strn = "true" if self.transcribe else "false"

bandwidth/voice/bxml/verbs/start_recording.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class StartRecording(AbstractBxmlVerb):
1717

1818
def __init__(self, tag=None, username=None, password=None, recording_available_url=None, recording_available_method=None,
19-
file_format=None, multi_channel=None, transcribe=None, transcription_available_url=None, transcription_available_method=None):
19+
file_format=None, multi_channel=None, detect_language=None, transcribe=None, transcription_available_url=None, transcription_available_method=None):
2020
"""
2121
Initializes the Record class with the following parameters
2222
@@ -27,6 +27,7 @@ def __init__(self, tag=None, username=None, password=None, recording_available_u
2727
:param str recording_available_method: HTTP method for record available callback
2828
:param str file_format: The file format to save the recording in
2929
:param bool multi_channel: Whether or not to record the channels separately (default is false, 1 recording)
30+
:param bool detect_language: Indicates that the recording may not be in English, and the transcription service will need to detect the dominant language the recording is in and transcribe accordingly. Current supported languages are English, French, and Spanish.
3031
:param bool transcribe: True to transcribe the recording on completion, False otherwise
3132
:param str transcription_available_url: URL to send the transcriptionAvailable event to.
3233
:param str transcription_available_method: The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST
@@ -38,6 +39,7 @@ def __init__(self, tag=None, username=None, password=None, recording_available_u
3839
self.recording_available_method = recording_available_method
3940
self.file_format = file_format
4041
self.multi_channel = multi_channel
42+
self.detect_language = detect_language
4143
self.transcribe = transcribe
4244
self.transcription_available_url = transcription_available_url
4345
self.transcription_available_method = transcription_available_method
@@ -60,6 +62,10 @@ def to_bxml(self):
6062
#Convert True to "true", or False to "false"
6163
strn = "true" if self.multi_channel else "false"
6264
root.set("multiChannel", strn)
65+
if self.detect_language is not None:
66+
#Convert True to "true", or False to "false"
67+
strn = "true" if self.detect_language else "false"
68+
root.set("detectLanguage", strn)
6369
if self.transcribe is not None:
6470
#Convert True to "true", or False to "false"
6571
strn = "true" if self.transcribe else "false"

bandwidth/voice/models/transcribe_recording_request.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010

1111
class TranscribeRecordingRequest(object):
12-
1312
"""Implementation of the 'TranscribeRecordingRequest' model.
1413
1514
TODO: type model description here.
1615
1716
Attributes:
17+
detect_language (bool): Indicates that the recording may not be in English, and the transcription service will need to detect the dominant language the recording is in and transcribe accordingly. Current supported languages are English, French, and Spanish.
1818
callback_url (string): TODO: type description here.
1919
callback_method (CallbackMethodEnum): TODO: type description here.
2020
username (string): TODO: type description here.
@@ -26,6 +26,7 @@ class TranscribeRecordingRequest(object):
2626

2727
# Create a mapping from Model property names to API property names
2828
_names = {
29+
"detect_language": "detectLanguage",
2930
"callback_url": 'callbackUrl',
3031
"callback_method": 'callbackMethod',
3132
"username": 'username',
@@ -35,6 +36,7 @@ class TranscribeRecordingRequest(object):
3536
}
3637

3738
def __init__(self,
39+
detect_language=None,
3840
callback_url=None,
3941
callback_method=None,
4042
username=None,
@@ -44,6 +46,7 @@ def __init__(self,
4446
"""Constructor for the TranscribeRecordingRequest class"""
4547

4648
# Initialize members of the class
49+
self.detect_language = detect_language
4750
self.callback_url = callback_url
4851
self.callback_method = callback_method
4952
self.username = username
@@ -69,6 +72,7 @@ def from_dictionary(cls,
6972
return None
7073

7174
# Extract variables from the dictionary
75+
detect_language = dictionary.get('detectLanguage')
7276
callback_url = dictionary.get('callbackUrl')
7377
callback_method = dictionary.get('callbackMethod')
7478
username = dictionary.get('username')
@@ -77,7 +81,8 @@ def from_dictionary(cls,
7781
callback_timeout = dictionary.get('callbackTimeout')
7882

7983
# Return an object of this model
80-
return cls(callback_url,
84+
return cls(detect_language,
85+
callback_url,
8186
callback_method,
8287
username,
8388
password,

0 commit comments

Comments
 (0)