{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import requests\n", "\n", "def transcribe_audio(file_path: str, server_url: str = \"\"):\n", " \"\"\"\n", " Отправляет аудиофайл на сервер для распознавания и возвращает результат.\n", "\n", " Args:\n", " file_path: Путь к локальному аудиофайлу.\n", " server_url: URL сервера (по умолчанию \"\").\n", "\n", " Returns:\n", " Распознанный текст.\n", " \"\"\"\n", " try:\n", " # Открываем файл для отправки\n", " with open(file_path, \"rb\") as audio_file:\n", " # Формируем запрос\n", " files = {\"file\": (file_path, audio_file)}\n", " response = requests.post(f\"{server_url}/v1/audio/transcriptions\", files=files)\n", "\n", " # Проверяем статус ответа\n", " if response.status_code == 200:\n", " return response.json()\n", " else:\n", " print(f\"Ошибка: {response.status_code}\")\n", " print(response.json())\n", " return None\n", "\n", " except Exception as e:\n", " print(f\"Ошибка при отправке файла: {e}\")\n", " return None\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Запуск транскрибации\n", "server=\"http:192.168.1.176:5042\"\n", "file=\"/Users/serge/Downloads/emToQc8pxaI_audio.mp3\"\n", "text = transcribe_audio(file, server)\n", "\n", "print(text)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import secrets\n", "import pyperclip # Import the pyperclip library\n", "\n", "def generate_token(num_groups: int, group_length: int) -> str:\n", " \"\"\"\n", " Generates a token with a specified number of groups and length for each group.\n", "\n", " Args:\n", " num_groups (int): The number of groups in the token.\n", " group_length (int): The length of each group.\n", "\n", " Returns:\n", " str: The generated token.\n", " \"\"\"\n", " groups = [secrets.token_urlsafe(group_length) for _ in range(num_groups)]\n", " return \"-\".join(groups)\n", "\n", "if __name__ == \"__main__\":\n", " num_groups = 4\n", " group_length = 8\n", " token = generate_token(num_groups, group_length)\n", " print(token)\n", "\n", " # Copy the token to the clipboard\n", " pyperclip.copy(token)\n", " print(\"Token copied to clipboard!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "wpc", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }