async def delete_one_channel(channel_id): try: if not ObjectId.is_valid(channel_id): return {"error": "ObjectId is not valid"} await delete(channel_id) return json({"message": "Channel successfully deleted."}, status=200) except Exception as error: return json({"error": error})
async def delete_existing_board(board_id): try: if not ObjectId.is_valid(board_id): return {"error": "ObjectId is not valid"} await delete(board_id) return {"message": "Board successfully deleted."} except Exception as error: return json({"error": error})
async def edit_existing_channel(data, channel_id): try: if not ObjectId.is_valid(channel_id): return {"error": "ObjectId is not valid"} edited_object = await update(data, channel_id) final = loads(dumps(edited_object)) return final except Exception as error: return json({"error": error})
async def edit_existing_board(data, board_id): try: if not ObjectId.is_valid(board_id): return {"error": "ObjectId is not valid"} response = await update(data, board_id) final = loads(dumps(response)) return final except Exception as error: return json({"error": error})
async def get_board_msgs(board_id): try: if not ObjectId.is_valid(board_id): return {"error": "ObjectId is not valid"} messages = await get_messages_by_board(board_id) final = loads(dumps(messages)) if final: return final return [] except Exception as error: return json({"error": error})
async def get_single_existing_channel(channel_id): try: if not ObjectId.is_valid(channel_id): return {"error": "ObjectId is not valid"} channel = await get_channel(channel_id) final = loads(dumps(channel)) if final: return final return [] except Exception as error: return json({"error": error})
async def get_boards_by_channel(channel_id): try: if not ObjectId.is_valid(channel_id): return {"error": "ObjectId is not valid"} response = await get_boards_by_channel_id(channel_id) final = loads(dumps(response)) if final: return final return [] except Exception as error: return json({"error": error})
async def get_single_existing_board(board_id): try: if not ObjectId.is_valid(board_id): return {"error": "ObjectId is not valid"} response = await get_board(board_id) final = loads(dumps(response)) if final: return final return [] except Exception as error: return json({"error": error})
async def get_single_msg(message_id): try: if not ObjectId.is_valid(message_id): return {"error": "ObjectId is not valid"} message = await get_message(message_id) final = loads(dumps(message)) if final: return final return [] except Exception as error: return json({"error": error})
def transcribe(self, path, timeout="auto", delete_after=True): """ Transcribe an audio file. The blocking transcribe operation (timeout >=0) does not guarantee the execution of all callbacks. Each callback should have its own event operations. Parameters ---------- path : str Path of the audio file. timeout : str or float, optional Sets a timeout (in seconds) fot the result operation If < 0, starts transcription and returns promptly only with the audio_id If == 0, waits indefinitely If 'auto', the timeout is set as the max between 30 and the audio length in seconds. Default: 'auto' delete_after : bool, optional Whether the results are deleted on the server after processed. Only meaningful if timeout < 0, otherwise it should be passed to the wait_result method. Default: True Returns ------- Only the audio id if timeout < 0, or a tuple (audio_id: str, result: dict) """ if timeout == "auto": with sf.SoundFile(path) as f: timeout = len(f) / f.samplerate timeout = max(30, timeout) elif not isinstance(timeout, numbers.Number): raise ValueError("Invalid value for timeout: {}".format(timeout)) # Upload audio file. Currently only expects r = self.api.audiofile_upload(path) r.raise_for_status() audio_id = next(iter(r.json().values())).split("/")[-1] if not ObjectId.is_valid(audio_id): raise ValueError(audio_id) # Set webhooks in the request webhook_root = "{}://{}:{}".format(self._webhook_protocol, self._webhook_host, self._webhook_port) webhooks = [webhook_root] webhooks += [ "{}/{}".format(webhook_root, name) for name in self._callbacks ] # Init events and start transcription. Return audio_id if timeout < 0 self._result_events[audio_id]["__root__"] = Event() for name in self._callbacks: self._result_events[audio_id][name] = Event() self.api.transcription_start(audio_id, request_args={"webhook": webhooks}) if timeout < 0: return audio_id return audio_id, self.wait_result(audio_id, timeout, delete_after)