55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
# This file is part of Gajim.
|
|
#
|
|
# Gajim is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import pickle
|
|
import sys
|
|
import traceback
|
|
|
|
|
|
def _respond(response: dict) -> None:
|
|
pickle.dump(response, sys.stdout.buffer)
|
|
sys.stdout.buffer.flush()
|
|
|
|
|
|
def main() -> None:
|
|
model = None
|
|
while True:
|
|
try:
|
|
cmd = pickle.load(sys.stdin.buffer)
|
|
except EOFError:
|
|
return
|
|
try:
|
|
op = cmd['op']
|
|
if op == 'load':
|
|
import onnx_asr
|
|
model = onnx_asr.load_model(
|
|
cmd['model_id'], cmd.get('model_path') or None)
|
|
_respond({'ok': True})
|
|
elif op == 'recognize':
|
|
text = model.recognize(cmd['audio'])
|
|
_respond({'ok': True, 'text': text})
|
|
else:
|
|
_respond({'ok': False, 'error': f'unknown op: {op}'})
|
|
except Exception as e:
|
|
_respond({
|
|
'ok': False,
|
|
'error': f'{type(e).__name__}: {e}',
|
|
'traceback': traceback.format_exc(),
|
|
})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|