Repository: psychopy/psychopy

Issue:
Transcription not working with built-in engine
I am trying ot launch the stroopVoice Demo, using the built-in engine for the transcription of the audio. However, I get the following error:

```
Generating PsychoPy script...

## Running: /Applications/PsychoPy.app/Contents/Resources/PsychoPy3 Demos/Experiments/stroopVoice/stroopVoice_lastrun.py ##
105.5928     INFO     Loaded monitor calibration from ['2022_05_27 18:48']
2022-07-01 16:32:07.511 python[8565:284570] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/qr/qxwlpzjn3jqf4f9yqt3cyrl00000gn/T/org.opensciencetools.psychopy.savedState
Fontconfig warning: ignoring UTF-8: not a valid region tag
||PaMacCore (AUHAL)|| Error on line 520: err=''!dat'', msg=Audio Device: Unsupported Format
Traceback (most recent call last):
||PaMacCore (AUHAL)|| Error on line 520: err=''!dat'', msg=Audio Device: Unsupported Format
4.1791     WARNING     /Users/simone/.psychopy3/fonts/Consolas.truetype doesn't have valid font family name
  File "/Applications/PsychoPy.app/Contents/Resources/PsychoPy3 Demos/Experiments/stroopVoice/stroopVoice_lastrun.py", line 391, in <module>
    micRespClip, micRespScript = micResp.bank(
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/sound/microphone.py", line 930, in bank
    self.lastScript = self.lastClip.transcribe(
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/sound/audioclip.py", line 753, in transcribe
    return transcribe(
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/sound/transcribe.py", line 347, in transcribe
    return recognizeSphinx(
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/sound/transcribe.py", line 518, in recognizeSphinx
    respAPI = _recogBase.recognize_sphinx(audioData, **config)
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/speech_recognition/__init__.py", line 725, in recognize_sphinx
    assert keyword_entries is None or all(isinstance(keyword, (type(""), type(u""))) and 0 <= sensitivity <= 1 for keyword, sensitivity in keyword_entries), "``keyword_entries`` must be ``None`` or a list of pairs of strings and numbers between 0 and 1"
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/speech_recognition/__init__.py", line 725, in <genexpr>
    assert keyword_entries is None or all(isinstance(keyword, (type(""), type(u""))) and 0 <= sensitivity <= 1 for keyword, sensitivity in keyword_entries), "``keyword_entries`` must be ``None`` or a list of pairs of strings and numbers between 0 and 1"
ValueError: not enough values to unpack (expected 2, got 1)
################# Experiment ended with exit code 1 [pid:8565] #################
```

I am using Psychopy v2022.1.4 on macOs Monterey 12.4

Thanks!


Discussion:

Resolving patch:
diff --git a/psychopy/sound/transcribe.py b/psychopy/sound/transcribe.py
--- a/psychopy/sound/transcribe.py
+++ b/psychopy/sound/transcribe.py
@@ -502,7 +502,8 @@ def recognizeSphinx(audioClip=None, language='en-US', expectedWords=None,
     config['language'] = language  # sphinx users en-us not en-US
     config['show_all'] = False
     if expectedWords is not None:
-        config['keyword_entries'] = zip(_parseExpectedWords(expectedWords))
+        words, sens = _parseExpectedWords(expectedWords)
+        config['keyword_entries'] = tuple(zip(words, sens))
 
     # convert audio to format for transcription
     sampleWidth = 2  # two bytes per sample


Test patch: