forked from Azure-Samples/cognitive-services-speech-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·81 lines (67 loc) · 2.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
import speech_sample
import intent_sample
import translation_sample
from collections import OrderedDict
import platform
eofkey = 'Ctrl-Z' if "Windows" == platform.system() else 'Ctrl-D'
samples = OrderedDict([
(speech_sample, [
speech_sample.speech_recognize_once_from_mic,
speech_sample.speech_recognize_once_from_file,
speech_sample.speech_recognize_once_from_file_with_customized_model,
speech_sample.speech_recognize_once_from_file_with_custom_endpoint_parameters,
speech_sample.speech_recognize_async_from_file,
speech_sample.speech_recognize_continuous_from_file,
speech_sample.speech_recognition_with_pull_stream,
speech_sample.speech_recognition_with_push_stream,
speech_sample.speech_recognize_keyword_from_microphone,
]), (intent_sample, [
intent_sample.recognize_intent_once_from_mic,
intent_sample.recognize_intent_once_async_from_mic,
intent_sample.recognize_intent_once_from_file,
intent_sample.recognize_intent_continuous,
]), (translation_sample, [
translation_sample.translation_once_from_mic,
translation_sample.translation_once_from_file,
translation_sample.translation_continuous,
])
])
def select():
print('select sample module, {} to abort'.format(eofkey))
modules = list(samples.keys())
for i, module in enumerate(modules):
print(i, module.__name__)
try:
num = int(input())
selected_module = modules[num]
except EOFError:
raise
except Exception as e:
print(e)
return
print('select sample function, {} to abort'.format(eofkey))
for i, fun in enumerate(samples[selected_module]):
print(i, fun.__name__)
try:
num = int(input())
selected_function = samples[selected_module][num]
except EOFError:
raise
except Exception as e:
print(e)
return
print('You selected: {}'.format(selected_function))
try:
selected_function()
except Exception as e:
print('Error running sample: {}'.format(e))
print()
while True:
try:
select()
except EOFError:
break