Skip to content

Commit 695b123

Browse files
committed
Update config and fix console window flashing (thanks @Qdrew!)
1 parent 7d3518d commit 695b123

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SpeechRecognition
1717
:target: https://pypi.python.org/pypi/SpeechRecognition/
1818
:alt: License
1919

20-
.. image:: https://img.shields.io/travis/Uberi/speech_recognition.svg
20+
.. image:: https://api.travis-ci.org/Uberi/speech_recognition.svg?branch=master
2121
:target: https://travis-ci.org/Uberi/speech_recognition
2222
:alt: Continuous Integration Test Results
2323

@@ -329,7 +329,7 @@ Also check out the `Python Baidu Yuyin API <https://github.com/DelightRun/PyBaid
329329
License
330330
-------
331331

332-
Copyright 2014-2017 `Anthony Zhang (Uberi) <https://uberi.github.io>`__. The source code for this library is available online at `GitHub <https://github.com/Uberi/speech_recognition>`__.
332+
Copyright 2014-2017 `Anthony Zhang (Uberi) <http://anthony-zhang.me/>`__. The source code for this library is available online at `GitHub <https://github.com/Uberi/speech_recognition>`__.
333333

334334
SpeechRecognition is made available under the 3-clause BSD license. See ``LICENSE.txt`` in the project's `root directory <https://github.com/Uberi/speech_recognition>`__ for more information.
335335

setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[bdist_wheel]
2+
# the `universal` setting means that the project runs unmodified on both Python 2 and 3,
3+
# and doesn't use any C extensions to Python
4+
universal=1

speech_recognition/__init__.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,18 @@ def __enter__(self):
210210

211211
# run the FLAC converter with the FLAC data to get the AIFF data
212212
flac_converter = get_flac_converter()
213+
if os.name == "nt": # on Windows, specify that the process is to be started without showing a console window
214+
startup_info = subprocess.STARTUPINFO()
215+
startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW # specify that the wShowWindow field of `startup_info` contains a value
216+
startup_info.wShowWindow = subprocess.SW_HIDE # specify that the console window should be hidden
217+
else:
218+
startup_info = None # default startupinfo
213219
process = subprocess.Popen([
214220
flac_converter,
215221
"--stdout", "--totally-silent", # put the resulting AIFF file in stdout, and make sure it's not mixed with any program output
216222
"--decode", "--force-aiff-format", # decode the FLAC file into an AIFF file
217223
"-", # the input FLAC file contents will be given in stdin
218-
], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
224+
], stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startup_info)
219225
aiff_data, stderr = process.communicate(flac_data)
220226
aiff_file = io.BytesIO(aiff_data)
221227
try:
@@ -412,12 +418,18 @@ def get_flac_data(self, convert_rate=None, convert_width=None):
412418
# run the FLAC converter with the WAV data to get the FLAC data
413419
wav_data = self.get_wav_data(convert_rate, convert_width)
414420
flac_converter = get_flac_converter()
421+
if os.name == "nt": # on Windows, specify that the process is to be started without showing a console window
422+
startup_info = subprocess.STARTUPINFO()
423+
startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW # specify that the wShowWindow field of `startup_info` contains a value
424+
startup_info.wShowWindow = subprocess.SW_HIDE # specify that the console window should be hidden
425+
else:
426+
startup_info = None # default startupinfo
415427
process = subprocess.Popen([
416428
flac_converter,
417429
"--stdout", "--totally-silent", # put the resulting FLAC file in stdout, and make sure it's not mixed with any program output
418430
"--best", # highest level of compression available
419431
"-", # the input FLAC file contents will be given in stdin
420-
], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
432+
], stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startup_info)
421433
flac_data, stderr = process.communicate(wav_data)
422434
return flac_data
423435

0 commit comments

Comments
 (0)