HoneyTian commited on
Commit
8c3a864
·
1 Parent(s): fff48e7
Files changed (2) hide show
  1. examples/asr.py +1 -1
  2. main.py +18 -7
examples/asr.py CHANGED
@@ -24,7 +24,7 @@ def get_args():
24
  )
25
  parser.add_argument(
26
  "--filename",
27
- default=(project_path / "data/speech/ja-JP/vm_2cb56b0c-e214-4a8d-ab01-a3a264d06c35_0.wav").as_posix(),
28
  type=str
29
  )
30
  parser.add_argument(
 
24
  )
25
  parser.add_argument(
26
  "--filename",
27
+ default=(project_path / "data/asr_examples/ja-JP/vm_2cb56b0c-e214-4a8d-ab01-a3a264d06c35_0.wav").as_posix(),
28
  type=str
29
  )
30
  parser.add_argument(
main.py CHANGED
@@ -6,7 +6,7 @@ from pathlib import Path
6
  import platform
7
  import re
8
 
9
- from project_settings import project_path, log_directory
10
  import log
11
 
12
  log.setup(log_directory=log_directory)
@@ -14,6 +14,7 @@ log.setup(log_directory=log_directory)
14
  import azure.cognitiveservices.speech as speechsdk
15
  import gradio as gr
16
 
 
17
  from toolbox.os.command import Command
18
 
19
  main_logger = logging.getLogger("main")
@@ -25,6 +26,16 @@ def shell(cmd: str):
25
 
26
  def get_args():
27
  parser = argparse.ArgumentParser()
 
 
 
 
 
 
 
 
 
 
28
  parser.add_argument(
29
  "--asr_examples_wav_dir",
30
  default=(project_path / "data/asr_examples").as_posix(),
@@ -49,14 +60,14 @@ def do_asr(filename: str, language: str, speech_key: str, service_region: str) -
49
  resp = speech_recognizer.recognize_once_async().get()
50
 
51
  if resp.reason == speechsdk.ResultReason.RecognizedSpeech:
52
- result = "Recognized: {}. ".format(resp.text)
53
  elif resp.reason == speechsdk.ResultReason.NoMatch:
54
- result = "No speech could be recognized: {}. ".format(resp.no_match_details)
55
  elif resp.reason == speechsdk.ResultReason.Canceled:
56
  cancellation_details = resp.cancellation_details
57
- result = "Speech Recognition canceled: {}. ".format(cancellation_details.reason)
58
  if cancellation_details.reason == speechsdk.CancellationReason.Error:
59
- result += "Error details: {}".format(cancellation_details.error_details)
60
  else:
61
  raise AssertionError
62
  return result
@@ -73,8 +84,8 @@ def main():
73
  asr_examples.append([
74
  filename.as_posix(),
75
  language,
76
- "require speech_key",
77
- "require service_region",
78
  ])
79
 
80
  title = "## Azure Service."
 
6
  import platform
7
  import re
8
 
9
+ from project_settings import log_directory
10
  import log
11
 
12
  log.setup(log_directory=log_directory)
 
14
  import azure.cognitiveservices.speech as speechsdk
15
  import gradio as gr
16
 
17
+ from project_settings import project_path, environment
18
  from toolbox.os.command import Command
19
 
20
  main_logger = logging.getLogger("main")
 
26
 
27
  def get_args():
28
  parser = argparse.ArgumentParser()
29
+ parser.add_argument(
30
+ "--speech_key",
31
+ default=environment.get("speech_key", "require speech_key"),
32
+ type=str
33
+ )
34
+ parser.add_argument(
35
+ "--service_region",
36
+ default=environment.get("service_region", "require service_region"),
37
+ type=str
38
+ )
39
  parser.add_argument(
40
  "--asr_examples_wav_dir",
41
  default=(project_path / "data/asr_examples").as_posix(),
 
60
  resp = speech_recognizer.recognize_once_async().get()
61
 
62
  if resp.reason == speechsdk.ResultReason.RecognizedSpeech:
63
+ result = "Recognized: `{}`. ".format(resp.text)
64
  elif resp.reason == speechsdk.ResultReason.NoMatch:
65
+ result = "No speech could be recognized: `{}`. ".format(resp.no_match_details)
66
  elif resp.reason == speechsdk.ResultReason.Canceled:
67
  cancellation_details = resp.cancellation_details
68
+ result = "Speech Recognition canceled: `{}`. ".format(cancellation_details.reason)
69
  if cancellation_details.reason == speechsdk.CancellationReason.Error:
70
+ result += "Error details: `{}`. ".format(cancellation_details.error_details)
71
  else:
72
  raise AssertionError
73
  return result
 
84
  asr_examples.append([
85
  filename.as_posix(),
86
  language,
87
+ args.speech_key,
88
+ args.service_region,
89
  ])
90
 
91
  title = "## Azure Service."