Skip to content

Commit 3af8e76

Browse files
wangbill-googlebusunkim96
authored andcommitted
test(speech): add v1 systests for longrunning / streaming recognize (#9285)
1 parent d84a219 commit 3af8e76

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

packages/google-cloud-speech/tests/system/gapic/v1/test_system_speech_v1.py

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,83 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import time
15+
import os
16+
import io
17+
import requests
1618

1719
from google.cloud import speech_v1
18-
from google.cloud.speech_v1 import enums
19-
from google.cloud.speech_v1.proto import cloud_speech_pb2
2020

2121

2222
class TestSystemSpeech(object):
2323
def test_recognize(self):
2424

25+
try:
26+
BUCKET = os.environ["GOOGLE_CLOUD_TESTS_SPEECH_BUCKET"]
27+
except KeyError:
28+
BUCKET = "cloud-samples-tests"
29+
2530
client = speech_v1.SpeechClient()
26-
language_code = "en-US"
27-
sample_rate_hertz = 44100
28-
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
31+
2932
config = {
30-
"language_code": language_code,
31-
"sample_rate_hertz": sample_rate_hertz,
32-
"encoding": encoding,
33+
"encoding": speech_v1.enums.RecognitionConfig.AudioEncoding.FLAC,
34+
"language_code": "en-US",
35+
"sample_rate_hertz": 16000,
3336
}
34-
uri = "gs://gapic-toolkit/hello.flac"
37+
38+
uri = "gs://{}/speech/brooklyn.flac".format(BUCKET)
3539
audio = {"uri": uri}
40+
3641
response = client.recognize(config, audio)
42+
43+
assert response.results[0].alternatives[0].transcript is not None
44+
45+
def test_long_running_recognize(self):
46+
47+
try:
48+
BUCKET = os.environ["GOOGLE_CLOUD_TESTS_SPEECH_BUCKET"]
49+
except KeyError:
50+
BUCKET = "cloud-samples-tests"
51+
52+
client = speech_v1.SpeechClient()
53+
54+
config = speech_v1.types.RecognitionConfig(
55+
encoding=speech_v1.enums.RecognitionConfig.AudioEncoding.FLAC,
56+
language_code="en-US",
57+
sample_rate_hertz=16000,
58+
)
59+
60+
uri = "gs://{}/speech/brooklyn.flac".format(BUCKET)
61+
audio = {"uri": uri}
62+
63+
response = client.long_running_recognize(config, audio)
64+
65+
assert response.result() is not None
66+
67+
def test_streaming_recognize(self):
68+
69+
try:
70+
BUCKET = os.environ["GOOGLE_CLOUD_TESTS_SPEECH_BUCKET"]
71+
except KeyError:
72+
BUCKET = "cloud-samples-tests"
73+
74+
client = speech_v1.SpeechClient()
75+
76+
config = speech_v1.types.RecognitionConfig(
77+
encoding=speech_v1.enums.RecognitionConfig.AudioEncoding.FLAC,
78+
language_code="en-US",
79+
sample_rate_hertz=16000,
80+
)
81+
streamingConfig = speech_v1.types.StreamingRecognitionConfig(config=config)
82+
83+
uri = "https://storage.googleapis.com/{}/speech/brooklyn.flac".format(BUCKET)
84+
streaming_requests = [
85+
speech_v1.types.StreamingRecognizeRequest(
86+
audio_content=requests.get(uri).content
87+
)
88+
]
89+
90+
responses = client.streaming_recognize(streamingConfig, streaming_requests)
91+
92+
for response in responses:
93+
for result in response.results:
94+
assert result.alternatives[0].transcript is not None

0 commit comments

Comments
 (0)