-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcapture2.py
More file actions
117 lines (108 loc) · 3.7 KB
/
capture2.py
File metadata and controls
117 lines (108 loc) · 3.7 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import logging
import collections, queue, os, os.path
import numpy as np
#import pyaudio
import wave
import webrtcvad
from halo import Halo
from scipy import signal
import websockets
import asyncio
import traceback
import transcribe
import translate
# import punctuate
logging.basicConfig(level=20)
logger = logging.getLogger('websockets')
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
def make_iter():
loop = asyncio.get_event_loop()
queue = asyncio.Queue()
def put(*args):
loop.call_soon_threadsafe(queue.put_nowait, args)
return queue, put
def main(source_lang, target_lang):
# folder = "C:/Program Files (x86)/Steam/steamapps/common/NeosVR/data/tmp/"
#folder = "/home/guillefix/.steam/steamapps/common/NeosVR/data/tmp/"
folder = "/root/NeosVR/data/tmp/"
# Start audio with VAD
async def translator():
async for file in transcribe.transcribe_tokenizer_folder(folder):
# naming convention - ID2C00_voice_tmp_[guid].wav
# if file is not None:
# username = str(file).split("_voice_")[0]
# text = transcribe.transcribe_tokenizer(file)
try:
text = transcribe.transcribe_google(file)
##translation = translate.translate(text, source_lang, target_lang)
yield text
except Exception as e:
print(e)
yield ""
# punctuated = punctuate.punctuate(text.lower())
# print("Recognized: %s" % punctuated)
# if text is None:
# yield "hi"
# else:
# yield text
# yield punctuated
# yield "hi"
# translation = translate.translate(punctuated, source_lang, target_lang)
# translation = punctuated
# print("Translation: %s" % translation)
# yield translation
# os.remove(vad_file)
async def test_generator():
while True:
yield "hi"
await asyncio.sleep(2)
async def test_generator2():
things = test_generator()
async for thing in things:
yield thing
# #
async def send_result(websocket, path):
# while not websocket.open:
# await asyncio.sleep(0.1)
print("HOOO")
result = translator()
# result = test_generator2()
async for msg in result:
try:
if msg != "":
await websocket.send(msg)
# print("oooooo")
print(msg)
# await websocket.send("hi")
# await asyncio.sleep(1)
except Exception as e:
print(e)
traceback.print_exc()
break
# while True:
# try:
# msg = await result.__anext__()
# print(msg)
# # await websocket.send("hohohoho")
# await websocket.send(msg)
# # await asyncio.sleep(0.1)
# except Exception as e:
# print(e)
# traceback.print_exc()
# async def test():
# result = translator()
# async for msg in result:
# print(msg)
async def test2():
frames = vad_audio.vad_collector()
print(frames)
async for frame in frames:
if frame is not None:
print(frame)
# asyncio.get_event_loop().run_until_complete(test2())
##To connect with Neos websockets
asyncio.get_event_loop().run_until_complete(websockets.serve(send_result, 'localhost', 8765))
# asyncio.get_event_loop().run_until_complete(test())
asyncio.get_event_loop().run_forever()
# translator()