diff --git a/.github/workflows/generate_docs.yml b/.github/workflows/generate_docs.yml new file mode 100644 index 0000000..ea79266 --- /dev/null +++ b/.github/workflows/generate_docs.yml @@ -0,0 +1,38 @@ +name: Generate Documentation + +on: + push: + branches: + - main + +jobs: + generate-docs: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r scripts/requirements.txt + + - name: Run generate_docs.py + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + python scripts/generate_docs.py + + - name: Commit changes + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add . + git commit -m 'Update documentation with code samples and descriptions' + git push origin main diff --git a/.gitignore b/.gitignore index 13e71b0..1311b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ target/ **/bin/ **/obj/ + +#env +.env \ No newline at end of file diff --git a/documentation/README.md b/documentation/README.md new file mode 100644 index 0000000..5c3a503 --- /dev/null +++ b/documentation/README.md @@ -0,0 +1,58 @@ +# Documentation + +## Purpose + +This directory contains markdown files of all the sample code found in this project's `/languages` folder. These markdown files are used by Deepgram's community knowledge AI tool to provide a knowledge base of code. Since the tool cannot read code in specific code language files, these markdown files have been created. + +## Updating Languages + +If you update one of the languages that already exists in this project (for example `javascript` or `python`), you must also update the corresponding markdown file in this directory. To do so, uncomment the language in the `update_languages.yaml` file. This will trigger a GitHub action that will update the markdown file when the updated code is merged into the `main` branch. + +For example, if you update `javascript` and `python`, you will need to uncomment the following lines in the `update_languages.yaml` file: + +```yaml +languages: + # - "c" + # - "cpp" + # - "csharp" + # - "go" + # - "java" + - "javascript" + # - "php" + - "python" + # - "ruby" + # - "rust" + # - "swift" +``` + +## Adding Languages + +If you add a new language to this project, you will do the same thing as you did for updating an existing language. Simply add the language to the `update_languages.yaml` file. + +For example, if you add `rust` as a new language folder, you will need to add the following lines to the `update_languages.yaml` file: + +```yaml +languages: + # - "c" + # - "cpp" + # - "csharp" + # - "go" + # - "java" + # - "javascript" + # - "php" + # - "python" + # - "ruby" + - "rust" + # - "swift" +``` + +You must also add a config file inside the `/languages` folder. This config file will identify the target files to scrape. For example, if you add a new language called `rust`, you will need to create a config file called `rust.yaml` inside the `/languages/rust` folder. The config file should look like this: + +```yaml +target_files: + - "*.rs" +``` + +## Output + +If you have followed the steps above, you can expect to see an updated or newly-created markdown file in the documentation directory after your code is merged into the `main` branch. diff --git a/documentation/c-readme.md b/documentation/c-readme.md index e06aa30..df73457 100644 --- a/documentation/c-readme.md +++ b/documentation/c-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API with C and libcurl + +**Title:** Converting Local Audio File to Text using Deepgram API + +**Code Sample:** speech-to-text/prerecorded/local/libcurl/c_local.c + +**Description:** This C program uses the libcurl library to send a local audio file to the Deepgram API for speech-to-text conversion. The code initializes libcurl, sets request headers, reads the audio file into a buffer, and sends the audio data to the Deepgram API. It then checks for errors and cleans up. + ### speech-to-text/prerecorded/local/libcurl/c_local.c ```c @@ -67,6 +75,14 @@ int main(void) { ``` +## Speech-to-Text Conversion using Deepgram API with libcurl in C + +**Title:** Converting Remote Pre-recorded Speech to Text + +**Code Sample:** speech-to-text/prerecorded/remote/libcurl/c_remote.c + +**Description:** This C code uses the libcurl library to send a HTTP request to the Deepgram API. It sets the necessary headers and sends a JSON payload containing the URL of a pre-recorded audio file. The Deepgram API then processes this audio file and returns a transcription. + ### speech-to-text/prerecorded/remote/libcurl/c_remote.c ```c @@ -113,6 +129,14 @@ int main(void) { ``` +## Text-to-Speech Conversion using Deepgram API and libcurl in C + +**Title:** Converting Text to Speech Using Deepgram API and libcurl in C + +**Code Sample:** text-to-speech/libcurl/c_tts.c + +**Description:** This C code uses the Deepgram API and the libcurl library to convert a hardcoded text string into speech. The output is saved as an MP3 file. The program initializes libcurl, sets the request headers, URL, and data, performs the request, and then cleans up. + ### text-to-speech/libcurl/c_tts.c ```c diff --git a/documentation/cpp-readme.md b/documentation/cpp-readme.md index 3d62ba1..5e62c4a 100644 --- a/documentation/cpp-readme.md +++ b/documentation/cpp-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API with Local Audio File and libcurl in C++ + +**Title:** Converting Local Audio File to Text using Deepgram API and libcurl in C++ + +**Code Sample:** speech-to-text/prerecorded/local/libcurl/cplus_local.cpp + +**Description:** This C++ code uses the libcurl library to send a local audio file to the Deepgram API for speech-to-text conversion. It initializes libcurl, sets the request URL and headers, reads the audio file as binary data, and sends it as the request data. It then performs the request and checks for any errors. + ### speech-to-text/prerecorded/local/libcurl/cplus_local.cpp ```cpp @@ -64,6 +72,14 @@ int main() { ``` +## Speech-to-Text Conversion using Deepgram API with C++ and libcurl + +**Title:** Speech-to-Text Conversion for Remote Pre-recorded Audio Files + +**Code Sample:** speech-to-text/prerecorded/remote/libcurl/cplus_remote.cpp + +**Description:** This C++ code uses the libcurl library to send a HTTP request to Deepgram's API. It converts a remote pre-recorded audio file (specified by a URL) into text. The code includes initialization of libcurl, setting request URL and headers, performing the request and error checking. + ### speech-to-text/prerecorded/remote/libcurl/cplus_remote.cpp ```cpp @@ -113,6 +129,14 @@ int main() { ``` +## Text-to-Speech Conversion using Deepgram API in C++ + +**Title:** Text-to-Speech Conversion with Deepgram API + +**Code Sample:** text-to-speech/libcurl/cplus_tts.cpp + +**Description:** This C++ code uses the libcurl library and Deepgram API to convert text into speech. It sends a HTTP request to the Deepgram API with the text to be converted and saves the response (the speech version of the text) as an MP3 file. + ### text-to-speech/libcurl/cplus_tts.cpp ```cpp diff --git a/documentation/csharp-readme.md b/documentation/csharp-readme.md index 4bfc348..fc79722 100644 --- a/documentation/csharp-readme.md +++ b/documentation/csharp-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API + +**Title:** Converting Pre-recorded Audio to Text using HTTP Client in C# + +**Code Sample:** speech-to-text/prerecorded/local/httpclient/Program.cs + +**Description:** This C# code uses the Deepgram API to convert a pre-recorded audio file to text. It reads the audio file as binary data, sends it to the Deepgram API, and then outputs the transcribed text. The code also handles errors and unsuccessful requests. + ### speech-to-text/prerecorded/local/httpclient/Program.cs ```csharp @@ -48,6 +56,14 @@ class Program ``` +## Assembly Attributes Setting for .NET Core Application + +**Title:** Setting Assembly Attributes in .NET Core + +**Code Sample:** speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs + +**Description:** This code sets the assembly attributes for a .NET Core application. It specifies that the target framework for the application is .NET Core 7.0. + ### speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs ```csharp @@ -58,6 +74,14 @@ using System.Reflection; ``` +## Assembly Information for Local_HttpClient + +**Title:** Assembly Information Configuration + +**Code Sample:** speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/Local_HttpClient.AssemblyInfo.cs + +**Description:** This auto-generated code provides assembly information for a Local_HttpClient application. It includes details like company name, product name, assembly version, and configuration settings. Changes to this file may affect the application's behavior. + ### speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/Local_HttpClient.AssemblyInfo.cs ```csharp @@ -86,6 +110,14 @@ using System.Reflection; ``` +## Global Usings for HttpClient in Speech-to-Text Conversion + +**Title:** Global Namespace Declarations for Speech-to-Text Conversion + +**Code Sample:** speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/Local_HttpClient.GlobalUsings.g.cs + +**Description:** This code defines global namespaces that are used throughout the application for a speech-to-text conversion program. It includes System, IO, Linq, HttpClient, and threading libraries. + ### speech-to-text/prerecorded/local/httpclient/obj/Debug/net7.0/Local_HttpClient.GlobalUsings.g.cs ```csharp @@ -100,6 +132,14 @@ global using global::System.Threading.Tasks; ``` +## Speech-to-Text Conversion using Deepgram API with HttpClient + +**Title:** Converting Pre-recorded Remote Audio to Text using HttpClient in C# + +**Code Sample:** speech-to-text/prerecorded/remote/httpclient/Program.cs + +**Description:** This C# program uses the HttpClient class to send a POST request to the Deepgram API. It converts a pre-recorded remote audio file (spacewalk.wav) into text and prints the response. If an error occurs, it prints the status code. + ### speech-to-text/prerecorded/remote/httpclient/Program.cs ```csharp @@ -143,6 +183,14 @@ class Program ``` +## .NET 7.0 Assembly Attributes Declaration + +**Title:** Assembly Attributes for .NET 7.0 + +**Code Sample:** speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs + +**Description:** This code is auto-generated and sets the target framework for a .NET 7.0 application. It uses the System.Runtime.Versioning.TargetFrameworkAttribute to specify the version and display name of the framework. + ### speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs ```csharp @@ -153,6 +201,14 @@ using System.Reflection; ``` +## Global Usings in .NET 7.0 for HttpClient in Speech-to-Text Conversion + +**Title:** Global Usings for Speech-to-Text Conversion with HttpClient + +**Code Sample:** speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/Remote_HttpClient.GlobalUsings.g.cs + +**Description:** This auto-generated code declares global usings for various .NET classes. It simplifies the code in the rest of the application by allowing these classes to be used without specifying their namespaces each time. The classes include System, IO, Linq, HttpClient, and threading-related classes, which are commonly used in speech-to-text conversion applications. + ### speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/Remote_HttpClient.GlobalUsings.g.cs ```csharp @@ -167,6 +223,14 @@ global using global::System.Threading.Tasks; ``` +## Assembly Information for Remote HttpClient + +**Title:** Assembly Information for Remote HttpClient + +**Code Sample:** speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/Remote_HttpClient.AssemblyInfo.cs + +**Description:** This auto-generated code provides assembly information for a Remote HttpClient application. It includes details such as company, configuration, product, title, and version attributes. Any changes to this file may cause incorrect behavior and will be lost if the code is regenerated. + ### speech-to-text/prerecorded/remote/httpclient/obj/Debug/net7.0/Remote_HttpClient.AssemblyInfo.cs ```csharp @@ -195,6 +259,14 @@ using System.Reflection; ``` +## Text-to-Speech Conversion Using Deepgram API + +**Title:** Converting Text to Speech using Deepgram API in C# + +**Code Sample:** text-to-speech/httpclient/Program.cs + +**Description:** This C# code sample uses the Deepgram API to convert a text string into speech. The resultant audio is then saved as an MP3 file. The HttpClient class is used to send a POST request to the Deepgram API, and the response is streamed into a binary file. The API key and output file path are configurable. + ### text-to-speech/httpclient/Program.cs ```csharp @@ -258,6 +330,14 @@ class Program } ``` +## .NET Core 7.0 Assembly Attributes Configuration + +**Title:** Setting Target Framework for .NET Core 7.0 + +**Code Sample:** text-to-speech/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs + +**Description:** This code sets the target framework for a .NET Core application to version 7.0 by using the TargetFrameworkAttribute in the System.Runtime.Versioning namespace. + ### text-to-speech/httpclient/obj/Debug/net7.0/.NETCoreApp,Version=v7.0.AssemblyAttributes.cs ```csharp @@ -268,6 +348,12 @@ using System.Reflection; ``` +**Title:** Global Usings in Text-to-Speech HttpClient Application + +**Code Sample:** text-to-speech/httpclient/obj/Debug/net7.0/TTS_HttpClient.GlobalUsings.g.cs + +**Description:** This code defines global usings for a Text-to-Speech application using HttpClient. It includes libraries for handling system operations, I/O, LINQ, HTTP requests, and asynchronous programming. + ### text-to-speech/httpclient/obj/Debug/net7.0/TTS_HttpClient.GlobalUsings.g.cs ```csharp @@ -282,6 +368,13 @@ global using global::System.Threading.Tasks; ``` +## Assembly Information for Text-to-Speech HttpClient + +**Title:** Assembly Attributes for TTS_HttpClient +**Code Sample:** text-to-speech/httpclient/obj/Debug/net7.0/TTS_HttpClient.AssemblyInfo.cs + +**Description:** This auto-generated code provides assembly information for a Text-to-Speech HttpClient, including company, configuration, file version, informational version, product, title, and version attributes. It is generated by MSBuild WriteCodeFragment class. + ### text-to-speech/httpclient/obj/Debug/net7.0/TTS_HttpClient.AssemblyInfo.cs ```csharp diff --git a/documentation/go-readme.md b/documentation/go-readme.md index b6af182..57f09b2 100644 --- a/documentation/go-readme.md +++ b/documentation/go-readme.md @@ -1,7 +1,10 @@ -**Title:** Speech-to-Text Conversion with Local Audio File using Deepgram API +## Speech-to-Text Conversion using Deepgram API with Local File + +**Title:** Sending Local Audio File to Deepgram for Speech-to-Text Conversion + **Code Sample:** speech-to-text/prerecorded/local/net_http/main.go -**Description:** This Go program uses the Deepgram API to convert a locally stored audio file into text. It opens the audio file, sends it to the Deepgram API, and prints out the text response. +**Description:** This code opens a local audio file, reads its content, and sends a POST request to the Deepgram API for speech-to-text conversion. It handles errors in file opening, reading, and API request creation. The response from the API is printed out. ### speech-to-text/prerecorded/local/net_http/main.go @@ -63,11 +66,13 @@ func main() { ``` -**Title:** Speech-to-Text Conversion with Remote Audio File using Deepgram API +## Speech-to-Text Conversion using Deepgram API with a Remote File + +**Title:** Converting Remote Audio File to Text using Deepgram API **Code Sample:** speech-to-text/prerecorded/remote/net_http/main.go -**Description:** This Go program uses the Deepgram API to convert speech to text from a remotely stored audio file. It sends a POST request with the URL of the audio file as payload, and prints the response from the API, which is the transcribed text. +**Description:** This Go code demonstrates how to use the Deepgram API to convert a remote audio file (specifically a .wav file) to text. The audio file is sent to the Deepgram API via a POST request, and the resulting text is printed out. ### speech-to-text/prerecorded/remote/net_http/main.go @@ -115,10 +120,11 @@ func main() { ``` -**Title:** Text-to-Speech Conversion using Deepgram API +**Title:** Text-to-Speech Conversion Using Deepgram API in Go + **Code Sample:** text-to-speech/net_http/main.go -**Description:** This Go code snippet uses the Deepgram API to convert a text string to speech. It sends a POST request to the Deepgram API with the text to be converted. If the request is successful, it saves the response, which is an MP3 file of the spoken text, to the local system. +**Description:** This Go code uses the Deepgram API to convert text to speech. It sends a POST request to the Deepgram API with a text payload and saves the returned audio data as an MP3 file. The API key is required for authentication. ### text-to-speech/net_http/main.go diff --git a/documentation/java-readme.md b/documentation/java-readme.md index 309d71b..afcf9cf 100644 --- a/documentation/java-readme.md +++ b/documentation/java-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API with HttpURLConnection + +**Title:** Converting Prerecorded Speech to Text with HttpURLConnection in Java + +**Code Sample:** speech-to-text/prerecorded/local/httpURLConnection/Main.java + +**Description:** This Java code uses HttpURLConnection to send an audio file to the Deepgram API, which then converts the speech in the audio file to text. The code handles connection setup, request configuration, audio file reading, and response processing. + ### speech-to-text/prerecorded/local/httpURLConnection/Main.java ```java @@ -72,6 +80,14 @@ public class Main { ``` +## Speech-to-Text Conversion using Deepgram API with OkHttpClient + +**Title:** Converting Pre-recorded Remote Audio to Text using Deepgram API and OkHttpClient + +**Code Sample:** speech-to-text/prerecorded/remote/okhttp3/Main.java + +**Description:** This Java code uses the Deepgram API and OkHttpClient to convert pre-recorded audio from a remote URL into text. It sends a POST request to the Deepgram API with the audio URL and API key, then prints the response or an error message. + ### speech-to-text/prerecorded/remote/okhttp3/Main.java ```java @@ -122,6 +138,14 @@ public class Main { ``` +## Text-to-Speech Conversion Using Deepgram API in Java + +**Title:** Text-to-Speech Conversion with Deepgram API + +**Code Sample:** text-to-speech/HttpClient/Main.java + +**Description:** This Java code uses the Deepgram API to convert a given text to speech. It sends a POST request with the text to be converted as a JSON payload. The response, which is an audio file, is saved in the specified output file. If the request fails, it prints the error message. + ### text-to-speech/HttpClient/Main.java ```java @@ -168,6 +192,14 @@ public class Main { ``` +## Text-to-Speech Conversion using Deepgram API and OkHttp3 Library + +**Title:** Converting Text to Speech with Deepgram API and OkHttp3 + +**Code Sample:** text-to-speech/okhttp3/Main.java + +**Description:** This Java code uses the Deepgram API and OkHttp3 library to convert a text string into speech. It sends a POST request to the Deepgram API with the text to be converted, and then saves the resulting audio file in mp3 format. + ### text-to-speech/okhttp3/Main.java ```java diff --git a/documentation/javascript-readme.md b/documentation/javascript-readme.md index 55dad1a..85828c9 100644 --- a/documentation/javascript-readme.md +++ b/documentation/javascript-readme.md @@ -1,3 +1,11 @@ +## Real-Time Speech-to-Text Conversion using Deepgram API and WebSocket + +**Title:** Real-Time Streaming Speech-to-Text Conversion + +**Code Sample:** speech-to-text/streaming/remote/axios/index.js + +**Description:** This code establishes a WebSocket connection to the Deepgram API for real-time speech-to-text conversion. It fetches a live audio stream from a remote URL (BBC World Service in this case), pipes this data through a PassThrough stream, and sends it to the Deepgram API for transcription. It handles various events like streaming data, end of stream, and errors. The transcribed results are logged to the console. The WebSocket connection is closed gracefully when the audio stream ends or the process is terminated. + ### speech-to-text/streaming/remote/axios/index.js ```javascript @@ -77,6 +85,14 @@ process.on("SIGINT", () => { ``` +## Speech-to-Text Conversion using Deepgram API with Local Audio File + +**Title:** Converting Local Audio File to Text using Deepgram API + +**Code Sample:** speech-to-text/prerecorded/local/https/index.js + +**Description:** This Node.js script uses the Deepgram API to convert a local audio file to text. It reads the audio file as binary data, creates a HTTPS request with the appropriate headers and options, and sends the request to the Deepgram API. The response is then parsed and logged. + ### speech-to-text/prerecorded/local/https/index.js ```javascript @@ -131,6 +147,14 @@ req.end(); ``` +## Speech-to-Text Conversion using Deepgram API with Local Audio File + +**Title:** Converting Local Audio File to Text using Deepgram API + +**Code Sample:** speech-to-text/prerecorded/local/fetch/index.js + +**Description:** This JavaScript code uses the Deepgram API to convert a locally stored audio file into text. It reads the audio file as binary data, sends a POST request to the Deepgram API with the audio data, and then handles the response. It requires the fs module for file system operations and fetch for making the API request. + ### speech-to-text/prerecorded/local/fetch/index.js ```javascript @@ -179,6 +203,14 @@ fs.readFile(audioFilePath, (err, audioData) => { ``` +## Speech-to-Text Conversion using Deepgram API with Local Audio File and Axios + +**Title:** Converting Local Audio File to Text using Deepgram API and Axios + +**Code Sample:** speech-to-text/prerecorded/local/axios/index.js + +**Description:** This JavaScript code uses Deepgram's API and the Axios library to convert a local audio file into text. It reads the audio file as binary data, then sends a POST request to Deepgram's API, handling both the response and any errors. + ### speech-to-text/prerecorded/local/axios/index.js ```javascript @@ -210,6 +242,14 @@ axios ``` +## Speech-to-Text Conversion with Remote Audio File using Deepgram API + +**Title:** Converting Remote Audio File to Text using Deepgram API + +**Code Sample:** speech-to-text/prerecorded/remote/fetch/index.js + +**Description:** This JavaScript code uses the Deepgram API to convert a remotely hosted audio file into text. It sends a POST request to the API with the audio file URL and logs the response or any errors. + ### speech-to-text/prerecorded/remote/fetch/index.js ```javascript @@ -245,6 +285,14 @@ fetch(url, { ``` +## Speech-to-Text Conversion using Deepgram API with Axios and Remote Audio File + +**Title:** Converting Remote Audio File to Text using Deepgram API and Axios + +**Code Sample:** speech-to-text/prerecorded/remote/axios/index.js + +**Description:** The provided code uses the Axios library to send a POST request to the Deepgram API, converting a remote audio file (in this case, "spacewalk.wav") into text. The response data is then logged to the console. + ### speech-to-text/prerecorded/remote/axios/index.js ```javascript @@ -278,6 +326,14 @@ axios ``` +## Unsafe Buffer Allocation in Node.js + +**Title:** Buffer Allocation with Error Handling + +**Code Sample:** node_modules/buffer-alloc-unsafe/index.js + +**Description:** This script creates a function that allocates an unsafe buffer of a given size in Node.js. It includes error handling for non-numeric or negative size inputs. If the Buffer.allocUnsafe method is available, it uses that; otherwise, it falls back to the deprecated Buffer constructor. + ### node_modules/buffer-alloc-unsafe/index.js ```javascript @@ -301,6 +357,14 @@ module.exports = allocUnsafe ``` +## DOMException Polyfill in Node.js + +**Title:** Implementing DOMException Polyfill + +**Code Sample:** node_modules/node-domexception/index.js + +**Description:** This code provides a polyfill for the DOMException in a Node.js environment. It uses the worker_threads module to create a MessageChannel and post a message. If an error occurs and it's a DOMException, the global DOMException object is set to the constructor of the error. + ### node_modules/node-domexception/index.js ```javascript @@ -323,6 +387,14 @@ module.exports = globalThis.DOMException ``` +## Time Conversion in Node.js + +**Title:** Time Conversion Helper Module + +**Code Sample:** node_modules/ms/index.js + +**Description:** This JavaScript code is a module in Node.js that provides functionality to parse a string or number into milliseconds and format a number of milliseconds into a string. It supports both short and long formats for time units like milliseconds, seconds, minutes, hours, days, and years. + ### node_modules/ms/index.js ```javascript @@ -481,6 +553,14 @@ function plural(ms, n, name) { ``` +## Handling WAVE Audio Files in Node.js + +**Title:** WAVE Audio File Reader and Writer + +**Code Sample:** node_modules/wav/index.js + +**Description:** This code provides classes for reading and writing WAVE audio files in Node.js. The `Reader` class reads WAVE files and outputs raw data, while the `Writer` and `FileWriter` classes create WAVE files from audio data. + ### node_modules/wav/index.js ```javascript @@ -524,6 +604,14 @@ exports.FileWriter = require('./lib/file-writer'); ``` +## Fetch API Implementation in Node.js + +**Title:** Fetch API Implementation in Node.js + +**Code Sample:** node_modules/node-fetch/src/index.js + +**Description:** This code is a Node.js implementation of the Fetch API, providing a request API compatible with window.fetch. It handles HTTP/HTTPS requests and responses, supports data URIs, redirection, error handling, and content encoding such as gzip, deflate, and brotli. It also handles aborting requests, chunked transfer encoding, and has utilities for working with headers, requests, and responses. + ### node_modules/node-fetch/src/index.js ```javascript @@ -947,6 +1035,14 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) { ``` +## Proxy Configuration in Node.js + +**Title:** Determining Proxy Settings Based on Environment Variables + +**Code Sample:** node_modules/proxy-from-env/index.js + +**Description:** This code is a Node.js module that provides a function to determine the correct proxy settings for a given URL based on environment variables. It parses the URL, checks for a set proxy, and decides whether to use it based on the hostname and port. It also handles 'NO_PROXY' settings. + ### node_modules/proxy-from-env/index.js ```javascript @@ -1061,6 +1157,12 @@ exports.getProxyForUrl = getProxyForUrl; ``` +**Title:** String Decoder in Node.js + +**Code Sample:** node_modules/string_decoder/index.js + +**Description:** This code is part of the Node.js 'string_decoder' module. It provides an interface for efficiently converting Buffer data to strings without breaking multi-byte characters. It handles different encodings such as 'utf8', 'ucs2', 'utf16le', and 'base64'. The code also includes methods to handle incomplete multi-byte characters. + ### node_modules/string_decoder/index.js ```javascript @@ -1288,6 +1390,14 @@ function base64DetectIncompleteChar(buffer) { ``` +## Fluent-ffmpeg Library Import + +**Title:** Importing Fluent-ffmpeg Library in Node.js + +**Code Sample:** node_modules/fluent-ffmpeg/index.js + +**Description:** This code is used to import the Fluent-ffmpeg library in a Node.js project. Fluent-ffmpeg is a library that provides a fluent API to interact with the FFmpeg command-line tool, which is used for handling multimedia data. + ### node_modules/fluent-ffmpeg/index.js ```javascript @@ -1295,6 +1405,14 @@ module.exports = require('./lib/fluent-ffmpeg'); ``` +## Buffer Allocation in Node.js + +**Title:** Buffer Allocation and Filling in Node.js + +**Code Sample:** node_modules/buffer-alloc/index.js + +**Description:** This JavaScript code is used in Node.js for allocating a buffer of a specified size and filling it with a given value. It uses 'buffer-fill' and 'buffer-alloc-unsafe' modules. The code also includes error handling for invalid size inputs. + ### node_modules/buffer-alloc/index.js ```javascript @@ -1333,6 +1451,14 @@ module.exports = function alloc (size, fill, encoding) { ``` +## MIME Type Management in Node.js + +**Title:** Handling MIME Types with the mime-types Library + +**Code Sample:** node_modules/mime-types/index.js + +**Description:** This JavaScript code is part of the mime-types library, used for handling MIME types in Node.js. It provides functionalities to look up MIME types, determine the default charset for a MIME type, get the default extension for a MIME type, and create a full Content-Type header given a MIME type or extension. It uses the mime-db database for its operations. + ### node_modules/mime-types/index.js ```javascript @@ -1527,6 +1653,13 @@ function populateMaps (extensions, types) { ``` +## Buffer Filling Operations in Node.js + +**Title:** Buffer Fill Operations in Node.js +**Code Sample:** node_modules/buffer-fill/index.js + +**Description:** This code provides functions for filling buffers in Node.js. It includes support for different data types (numbers, strings, buffers) and encodings. It also handles edge cases like out-of-range indexes and unrecognized encodings. + ### node_modules/buffer-fill/index.js ```javascript @@ -1646,6 +1779,14 @@ module.exports = fill ``` +## Asynckit Module Exportation in Node.js + +**Title:** Exporting Parallel, Serial, and SerialOrdered Functions with Asynckit + +**Code Sample:** node_modules/asynckit/index.js + +**Description:** This code exports three different functions (parallel, serial, and serialOrdered) from the Asynckit library in Node.js. This allows for asynchronous operations to be handled in different manners, improving efficiency and control over task execution. + ### node_modules/asynckit/index.js ```javascript @@ -1658,6 +1799,14 @@ module.exports = ``` +## Stream Parser for Node.js + +**Title:** Stream Parser for Node.js + +**Code Sample:** node_modules/stream-parser/index.js + +**Description:** This code is a Stream Parser for Node.js. It extends either Writable or Transform stream instances/subclasses with parsing API methods: _bytes, _skipBytes, and _passthrough. The parser buffers, skips, or passes through a specified number of bytes and then calls a callback function. This module is useful for handling stream data in chunks, improving performance and memory usage in Node.js applications. + ### node_modules/stream-parser/index.js ```javascript @@ -1963,6 +2112,14 @@ function trampoline (fn) { ``` +## Follow Redirects in Node.js using Follow-Redirects Library + +**Title:** Follow Redirects in HTTP/HTTPS Requests + +**Code Sample:** node_modules/follow-redirects/index.js + +**Description:** This JavaScript code is part of the Follow-Redirects library used in Node.js for handling HTTP and HTTPS requests that result in a redirection. The library wraps the native http and https modules to follow HTTP redirect responses automatically. It provides options to limit the number of redirects, track redirect chain, and customize headers across redirects. It also handles errors for invalid URLs, too many redirects, and exceeding the maximum body length. + ### node_modules/follow-redirects/index.js ```javascript @@ -2641,6 +2798,14 @@ module.exports.wrap = wrap; ``` +## Checking if an Object is an Array + +**Title:** Array Verification using isArray Function + +**Code Sample:** node_modules/isarray/index.js + +**Description:** This JavaScript code exports a function that checks if a given object is an array. It uses the built-in Array.isArray method, or, if that's not available, it uses the toString method of Object.prototype to compare the string representation of the object to '[object Array]'. + ### node_modules/isarray/index.js ```javascript @@ -2650,6 +2815,14 @@ module.exports = Array.isArray || function (arr) { ``` +## Converting Data URI to Buffer in Node.js + +**Title:** Data URI to Buffer Conversion + +**Code Sample:** node_modules/data-uri-to-buffer/dist/index.js + +**Description:** This JavaScript code exports a function that converts a Data URI into a Buffer instance in Node.js. It parses the metadata from the URI, determines the encoding type, and returns a Buffer object with the decoded data. The Buffer object also includes properties for MIME type and character set. + ### node_modules/data-uri-to-buffer/dist/index.js ```javascript @@ -2708,6 +2881,12 @@ export default dataUriToBuffer; //# sourceMappingURL=index.js.map ``` +**Title:** Blob Data Handling in Node.js + +**Code Sample:** node_modules/fetch-blob/index.js + +**Description:** This JavaScript code is a part of the 'fetch-blob' library used in Node.js for handling Blob data. It defines a Blob class with methods for creating new Blob objects, getting Blob size and type, converting Blob to text or ArrayBuffer, streaming Blob data, and slicing Blob data. It also includes a toIterator function for converting Blob or Uint8Array parts into an iterator. The Blob class is then exported for use in other modules. + ### node_modules/fetch-blob/index.js ```javascript @@ -2964,6 +3143,12 @@ export default Blob ``` +**Title:** Unwrapping and Exporting Axios Module + +**Code Sample:** node_modules/axios/index.js + +**Description:** This JavaScript code is part of the Axios library, used for making HTTP requests from node.js or XMLHttpRequests from the browser. It unwraps the Axios default export into named exports, allowing users to import specific functions or objects from the library. + ### node_modules/axios/index.js ```javascript @@ -3013,6 +3198,14 @@ export { ``` +## Axios Platform Configuration in Node.js + +**Title:** Platform Configuration with Axios and Node.js + +**Code Sample:** node_modules/axios/lib/platform/index.js + +**Description:** This code sample imports and exports the platform-specific configuration for Axios, a promise-based HTTP client for the browser and Node.js. It combines the utilities and platform-specific settings into a single module. + ### node_modules/axios/lib/platform/index.js ```javascript @@ -3026,6 +3219,14 @@ export default { ``` +## Browser-Specific Configurations for Axios + +**Title:** Axios Browser Configuration + +**Code Sample:** node_modules/axios/lib/platform/browser/index.js + +**Description:** This code exports browser-specific configurations for Axios, a promise-based HTTP client. It includes classes for working with URLSearchParams, FormData, and Blob objects, and recognizes various protocols. + ### node_modules/axios/lib/platform/browser/index.js ```javascript @@ -3045,6 +3246,14 @@ export default { ``` +## Node.js Platform Configuration in Axios + +**Title:** Configuring Node.js Specific Settings in Axios + +**Code Sample:** node_modules/axios/lib/platform/node/index.js + +**Description:** This code is part of Axios library which configures Node.js specific settings. It imports and exports classes like URLSearchParams and FormData, and specifies the protocols to be used. + ### node_modules/axios/lib/platform/node/index.js ```javascript @@ -3063,6 +3272,14 @@ export default { ``` +## Axios Default Configuration + +**Title:** Default Configuration and Utility Functions for Axios + +**Code Sample:** node_modules/axios/lib/defaults/index.js + +**Description:** This JavaScript file defines the default configuration and utility functions for Axios, a popular HTTP client for Node.js. It includes functions for transforming request and response data, handling timeouts, validating status codes, setting headers, and more. It also contains a safe stringification function to prevent JSON parsing errors. + ### node_modules/axios/lib/defaults/index.js ```javascript @@ -3230,6 +3447,14 @@ export default defaults; ``` +## Buffer Conversion in Node.js + +**Title:** Buffer Conversion Utility + +**Code Sample:** node_modules/buffer-from/index.js + +**Description:** This code is a utility module for converting different types of data (like strings and ArrayBuffer objects) to Buffer objects in Node.js. It provides backward compatibility by checking if modern Buffer API methods are available, and if not, it uses the deprecated Buffer constructor. + ### node_modules/buffer-from/index.js ```javascript @@ -3308,6 +3533,13 @@ module.exports = bufferFrom ``` +## Implementation of WebSocket in Node.js + +**Title:** WebSocket Module Initialization in Node.js +**Code Sample:** node_modules/ws/index.js + +**Description:** This code imports various components from the 'ws' library in Node.js and exports the WebSocket object. It sets up WebSocket streams, servers, receivers, and senders, making it ready for use in a Node.js application. + ### node_modules/ws/index.js ```javascript @@ -3327,6 +3559,14 @@ module.exports = WebSocket; ``` +## Detecting Electron Renderer Process + +**Title:** Electron Renderer Process Detection + +**Code Sample:** node_modules/debug/src/index.js + +**Description:** The code detects if the current process is an Electron renderer process. If it is, it exports the browser-specific debug module. Otherwise, it exports the Node.js-specific debug module. + ### node_modules/debug/src/index.js ```javascript @@ -3343,6 +3583,14 @@ if (typeof process !== 'undefined' && process.type === 'renderer') { ``` +## Importing MIME Type Database + +**Title:** Importing MIME Type Database in Node.js + +**Code Sample:** node_modules/mime-db/index.js + +**Description:** This code exports the MIME (Multipurpose Internet Mail Extensions) type database from a JSON file. It's part of the mime-db module, which provides a comprehensive list of MIME types based on the data from IANA (Internet Assigned Numbers Authority). + ### node_modules/mime-db/index.js ```javascript @@ -3361,6 +3609,14 @@ module.exports = require('./db.json') ``` +## Checking Execution Permissions in Node.js + +**Title:** Checking File Execution Permissions + +**Code Sample:** node_modules/isexe/index.js + +**Description:** This code checks if a file has execution permissions in a Node.js environment. It uses the 'fs' library and handles both Windows and Unix-like platforms. The code exports two functions, 'isexe' and 'isexe.sync', which asynchronously and synchronously check if a file is executable, respectively. + ### node_modules/isexe/index.js ```javascript @@ -3424,6 +3680,14 @@ function sync (path, options) { ``` +## Text-to-Speech Conversion using Deepgram API + +**Title:** Converting Text to Speech using Node.js and Deepgram API + +**Code Sample:** text-to-speech/https/index.js + +**Description:** This code uses the Deepgram API to convert a string of text ("Hello, how can I help you today?") into speech. The resulting audio is saved as an MP3 file. Node.js's https and fs modules are used for making HTTP requests and handling the file system. + ### text-to-speech/https/index.js ```javascript @@ -3466,6 +3730,14 @@ req.end(); ``` +## Text-to-Speech Conversion Using Deepgram API + +**Title:** Text-to-Speech Conversion and File Writing with Deepgram API + +**Code Sample:** text-to-speech/fetch/index.js + +**Description:** This script uses the Deepgram API to convert a text string to speech. It then saves the resulting audio data as an mp3 file. The script sends a POST request to the Deepgram API, handles the response, and writes the audio data to a file. + ### text-to-speech/fetch/index.js ```javascript @@ -3516,6 +3788,14 @@ fetch(url, options) ``` +## Text-to-Speech Conversion Using Deepgram API with Axios + +**Title:** Converting Text to Speech using Deepgram API and Axios + +**Code Sample:** text-to-speech/axios/index.js + +**Description:** This JavaScript code uses the Axios library to send a POST request to the Deepgram API, converting a given text string into speech. The speech is saved as an MP3 file. It uses stream response type to handle the audio data. + ### text-to-speech/axios/index.js ```javascript diff --git a/documentation/php-readme.md b/documentation/php-readme.md index 38e4a1a..0c83cf7 100644 --- a/documentation/php-readme.md +++ b/documentation/php-readme.md @@ -1,3 +1,9 @@ +**Title:** Speech-to-Text Conversion using Deepgram API with PHP and cURL + +**Code Sample:** speech-to-text/prerecorded/local/curl/index.php + +**Description:** This PHP script uses the cURL library to send a POST request to the Deepgram API, converting a pre-recorded .wav audio file to text. The response from the API is then printed. If there's an error, it is displayed instead. + ### speech-to-text/prerecorded/local/curl/index.php ```php @@ -43,6 +49,14 @@ curl_close($ch); ``` +## Speech-to-Text Conversion using Deepgram API with PHP + +**Title:** Converting Pre-recorded Remote Audio to Text with Deepgram API in PHP + +**Code Sample:** speech-to-text/prerecorded/remote/curl/index.php + +**Description:** This PHP script uses the Deepgram API to convert pre-recorded audio from a remote URL to text. It sends a POST request to the API with the audio file URL, receives the response in JSON format, and prints it. If an error occurs during the process, it prints the cURL error. + ### speech-to-text/prerecorded/remote/curl/index.php ```php @@ -97,6 +111,14 @@ curl_close($ch); ``` +## Text-to-Speech Conversion Using Deepgram API + +**Title:** Converting Text to Speech using Deepgram API in PHP + +**Code Sample:** text-to-speech/curl/index.php + +**Description:** This PHP script sends a request to Deepgram's API to convert text to speech. It uses the cURL library to make the request, passing the text "Hello, how can I help you today?" as JSON data. The API responds with an audio file which is saved as 'your_output_file.mp3'. + ### text-to-speech/curl/index.php ```php diff --git a/documentation/python-readme.md b/documentation/python-readme.md index 35d24d7..5f29119 100644 --- a/documentation/python-readme.md +++ b/documentation/python-readme.md @@ -1,3 +1,11 @@ +## Real-Time Speech-to-Text Conversion with Deepgram API using WebSockets + +**Title:** Real-Time Speech-to-Text Conversion + +**Code Sample:** speech-to-text/streaming/threading/main.py + +**Description:** This Python script uses the Deepgram API to convert real-time audio stream from a URL into text transcripts. It uses WebSocketApp from the websocket library to establish a WebSocket connection with Deepgram's 'listen' endpoint. The audio stream is fetched using the requests library and sent to the WebSocket in chunks. The received messages from the WebSocket are then processed to extract the transcripts. Threading is used to handle the audio streaming concurrently with the WebSocket connection. + ### speech-to-text/streaming/threading/main.py ```python @@ -63,6 +71,14 @@ ws.run_forever() ``` +## Real-time Speech-to-Text Conversion using Deepgram WebSocket API + +**Title:** Real-time Speech-to-Text Conversion + +**Code Sample:** speech-to-text/streaming/asyncio/main.py + +**Description:** This Python script uses the asyncio and aiohttp libraries to establish a WebSocket connection with the Deepgram API. It streams audio from a live BBC radio broadcast and sends it to the Deepgram API for real-time transcription. The transcriptions are then printed to the console. + ### speech-to-text/streaming/asyncio/main.py ```python @@ -132,6 +148,14 @@ if __name__ == "__main__": ``` +## Speech-to-Text Conversion using Deepgram API + +**Title:** Converting Pre-recorded Local Audio to Text with Deepgram API + +**Code Sample:** speech-to-text/prerecorded/local/requests/main.py + +**Description:** This script uses the Deepgram API to convert a pre-recorded local audio file to text. It sends a POST request with the audio file to the Deepgram API endpoint and prints the response in JSON format. + ### speech-to-text/prerecorded/local/requests/main.py ```python @@ -154,6 +178,14 @@ with open("/path/to/youraudio.wav", "rb") as audio_file: print(response.json()) ``` +## Speech-to-Text Conversion using Deepgram API with Local Audio Files + +**Title:** Converting Local Audio Files to Text with Deepgram API + +**Code Sample:** speech-to-text/prerecorded/local/http-client/main.py + +**Description:** This Python script uses the Deepgram API to convert a local audio file to text. It reads the audio file as binary data, sends it to the Deepgram API via a POST request, and prints the response. The Deepgram API key and audio file path are required inputs. + ### speech-to-text/prerecorded/local/http-client/main.py ```python @@ -198,6 +230,14 @@ conn.close() ``` +## Speech-to-Text Conversion using Deepgram API + +**Title:** Converting Pre-recorded Remote Audio to Text with Deepgram API + +**Code Sample:** speech-to-text/prerecorded/remote/requests/main.py + +**Description:** This code uses the Deepgram API to convert a pre-recorded remote audio file (spacewalk.wav) into text. It sends a HTTP request with necessary headers and data, and prints the response in JSON format. + ### speech-to-text/prerecorded/remote/requests/main.py ```python @@ -221,6 +261,14 @@ response = requests.post(url, headers=headers, json=data) print(response.json()) ``` +## Speech-to-Text Conversion using Deepgram API + +**Title:** Converting Pre-recorded Remote Audio to Text using HTTP Client in Python + +**Code Sample:** speech-to-text/prerecorded/remote/http-client/main.py + +**Description:** This Python script uses the http.client library to send a POST request to the Deepgram API, converting a pre-recorded audio file (spacewalk.wav) hosted remotely into text. The output is then printed to the console. + ### speech-to-text/prerecorded/remote/http-client/main.py ```python @@ -249,6 +297,14 @@ data = res.read() print(data.decode("utf-8")) ``` +## Text-to-Speech Conversion Using Deepgram API + +**Title:** Converting Text to Speech using Deepgram API + +**Code Sample:** text-to-speech/requests/main.py + +**Description:** This Python script uses the Deepgram API to convert a text string ("Hello, how can I help you today?") into speech. The resulting audio is saved as an MP3 file. The script uses the requests library to send a POST request, including the necessary headers and payload, to the Deepgram API. + ### text-to-speech/requests/main.py ```python @@ -274,6 +330,14 @@ else: ``` +## Text-to-Speech Conversion using Deepgram API + +**Title:** Converting Text to Speech using Deepgram API and Python's http.client + +**Code Sample:** text-to-speech/http-client/main.py + +**Description:** This Python script uses the Deepgram API to convert a given text into speech. The output is saved as an mp3 file. The http.client library is used to make a POST request to the API. + ### text-to-speech/http-client/main.py ```python diff --git a/documentation/ruby-readme.md b/documentation/ruby-readme.md index dece880..f63c4a7 100644 --- a/documentation/ruby-readme.md +++ b/documentation/ruby-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API and HTTParty + +**Title:** Local Audio File Speech-to-Text Conversion + +**Code Sample:** speech-to-text/prerecorded/local/httparty/main.rb + +**Description:** This Ruby script uses the HTTParty library to send a local audio file to the Deepgram API for speech-to-text conversion. The script reads the audio file as binary data, and then sends it as a POST request to the Deepgram API. The resulting transcription is then printed to the console. + ### speech-to-text/prerecorded/local/httparty/main.rb ```ruby @@ -30,6 +38,14 @@ puts response.body ``` +## Speech-to-Text Conversion using Deepgram API with Ruby + +**Title:** Converting Pre-recorded Audio to Text using Net::HTTP in Ruby + +**Code Sample:** speech-to-text/prerecorded/local/net-http/main.rb + +**Description:** This Ruby script uses the 'net/http' library to send a POST request to Deepgram's API, converting a pre-recorded audio file to text. The script reads an audio file, sends it to the Deepgram API, and prints the response, which contains the transcribed text. + ### speech-to-text/prerecorded/local/net-http/main.rb ```ruby @@ -66,6 +82,14 @@ puts response.body ``` +## Speech-to-Text Conversion using Deepgram API with HTTParty + +**Title:** Converting Pre-recorded Remote Audio to Text using Deepgram API and HTTParty + +**Code Sample:** speech-to-text/prerecorded/remote/httparty/main.rb + +**Description:** This Ruby script uses the HTTParty library to send a POST request to the Deepgram API, converting a pre-recorded remote audio file (spacewalk.wav) into text. The script defines the API endpoint, headers, and request body, and then outputs the response. + ### speech-to-text/prerecorded/remote/httparty/main.rb ```ruby @@ -93,6 +117,14 @@ response = HTTParty.post(url, headers: headers, body: body) puts response.body ``` +## Speech-to-Text Conversion using Deepgram API with Ruby + +**Title:** Converting Pre-recorded Remote Audio to Text using Deepgram API and Ruby + +**Code Sample:** speech-to-text/prerecorded/remote/net-http/main.rb + +**Description:** This Ruby script sends a POST request to the Deepgram API to transcribe a pre-recorded audio file (spacewalk.wav) located at a remote URL. It sets up the required headers, sends the request, and prints the response body. + ### speech-to-text/prerecorded/remote/net-http/main.rb ```ruby @@ -125,6 +157,14 @@ puts response.body ``` +## Text-to-Speech Conversion Using Deepgram API and HTTParty Library + +**Title:** Converting Text to Speech with Deepgram API and HTTParty + +**Code Sample:** text-to-speech/httparty/main.rb + +**Description:** This Ruby script uses the HTTParty library to send a POST request to the Deepgram API, converting a given text into speech. The output is saved as an MP3 file. If the request is successful, it will output 'File saved successfully', otherwise, it will display the error code and message. + ### text-to-speech/httparty/main.rb ```ruby @@ -152,6 +192,14 @@ end ``` +## Text-to-Speech Conversion using Deepgram API in Ruby + +**Title:** Converting Text to Speech using Deepgram API in Ruby + +**Code Sample:** text-to-speech/net-http/main.rb + +**Description:** This code uses the Deepgram API to convert a given text into speech. The output is saved as an MP3 file. It uses the Net::HTTP library in Ruby to make HTTP requests. The API key for Deepgram is required for authentication. + ### text-to-speech/net-http/main.rb ```ruby diff --git a/documentation/rust-readme.md b/documentation/rust-readme.md index eecd2a1..a232d47 100644 --- a/documentation/rust-readme.md +++ b/documentation/rust-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API + +**Title:** Remote Speech-to-Text Conversion with Deepgram API + +**Code Sample:** speech-to-text/remote/main.rs + +**Description:** This Rust code sample uses the Deepgram API to convert speech to text. It sends a POST request to the API with an audio file URL and then retrieves and prints the transcription. The reqwest and serde libraries are used for HTTP requests and serialization, respectively. + ### speech-to-text/remote/main.rs ```rust @@ -33,6 +41,14 @@ fn main() -> Result<(), Box> { } ``` +## Text-to-Speech Conversion Using Deepgram API with Reqwest Library + +**Title:** Converting Text to Speech Using Deepgram API and Reqwest in Rust + +**Code Sample:** text-to-speech/reqwest/main.rs + +**Description:** This Rust code uses the Deepgram API and the Reqwest library to convert a given text string to speech. The output is saved as an mp3 file. The program sends a POST request with the text to be converted in the request body, receives the audio data in the response, and writes it to a file. + ### text-to-speech/reqwest/main.rs ```rust diff --git a/documentation/swift-readme.md b/documentation/swift-readme.md index 2cd126b..ee6693b 100644 --- a/documentation/swift-readme.md +++ b/documentation/swift-readme.md @@ -1,3 +1,11 @@ +## Speech-to-Text Conversion using Deepgram API with URLSession in Swift + +**Title:** Converting Pre-recorded Speech to Text with URLSession in Swift + +**Code Sample:** speech-to-text/prerecorded/local/urlsession/main.swift + +**Description:** This Swift code sample uses the Deepgram API to convert pre-recorded speech to text. It reads an audio file as binary data, creates a URLRequest object to set the request headers and body, then uses URLSession to perform the request and process the response. + ### speech-to-text/prerecorded/local/urlsession/main.swift ```swift @@ -57,6 +65,14 @@ RunLoop.main.run() ``` +## Speech-to-Text Conversion using Deepgram API with Swift + +**Title:** Converting Pre-recorded Remote Audio to Text using Deepgram API in Swift + +**Code Sample:** speech-to-text/prerecorded/remote/urlsession/main.swift + +**Description:** This Swift code sample demonstrates how to use the Deepgram API to convert a pre-recorded audio file from a remote URL to text. It makes a POST request to the Deepgram API, and the response is parsed and printed to the console. + ### speech-to-text/prerecorded/remote/urlsession/main.swift ```swift @@ -108,6 +124,14 @@ RunLoop.main.run() ``` +## Text-to-Speech Conversion Using Deepgram API in Swift + +**Title:** Converting Text to Speech and Saving as MP3 File with Deepgram API + +**Code Sample:** text-to-speech/urlsession/main.swift + +**Description:** This Swift code uses the Deepgram API to convert a specified text string to speech, saving the resulting audio as an MP3 file. It creates a URL request, sends it via URLSession, and handles the response data, writing it to an MP3 file if successful. + ### text-to-speech/urlsession/main.swift ```swift diff --git a/documentation/update_languages.yaml b/documentation/update_languages.yaml new file mode 100644 index 0000000..cd7be23 --- /dev/null +++ b/documentation/update_languages.yaml @@ -0,0 +1,12 @@ +languages: + # - "c" + # - "cpp" + # - "csharp" + # - "go" + # - "java" + # - "javascript" + # - "php" + # - "python" + # - "ruby" + # - "rust" + # - "swift" diff --git a/languages/project_structure.yaml b/languages/project_structure.yaml deleted file mode 100644 index f0b92b8..0000000 --- a/languages/project_structure.yaml +++ /dev/null @@ -1,1153 +0,0 @@ -code-samples: - languages: - c: - files: - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - libcurl: - files: - - c_local.c - remote: - libcurl: - files: - - c_remote.c - text-to-speech: - libcurl: - files: - - c_tts.c - cpp: - files: - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - http: {} - libcurl: - files: - - cplus_local.cpp - remote: - libcurl: - files: - - cplus_remote.cpp - text-to-speech: - libcurl: - files: - - cplus_tts.cpp - csharp: - files: - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - httpclient: - bin: - Debug: - net7.0: - files: - - Local_HttpClient - - Local_HttpClient.deps.json - - Local_HttpClient.dll - - Newtonsoft.Json.dll - - Local_HttpClient.runtimeconfig.json - - Local_HttpClient.pdb - files: - - Local_HttpClient.csproj - - Program.cs - obj: - Debug: - net7.0: - files: - - .NETCoreApp,Version=v7.0.AssemblyAttributes.cs - - Local_HttpClient.GeneratedMSBuildEditorConfig.editorconfig - - Local_HttpClient.csproj.CopyComplete - - Local_HttpClient.csproj.AssemblyReference.cache - - Local_HttpClient.genruntimeconfig.cache - - Local_HttpClient.AssemblyInfoInputs.cache - - apphost - - Local_HttpClient.assets.cache - - Local_HttpClient.AssemblyInfo.cs - - Local_HttpClient.dll - - Local_HttpClient.csproj.FileListAbsolute.txt - - Local_HttpClient.csproj.CoreCompileInputs.cache - - Local_HttpClient.pdb - - Local_HttpClient.GlobalUsings.g.cs - ref: - files: - - Local_HttpClient.dll - refint: - files: - - Local_HttpClient.dll - files: - - Local_HttpClient.csproj.nuget.dgspec.json - - project.nuget.cache - - Local_HttpClient.csproj.nuget.g.props - - project.assets.json - - Local_HttpClient.csproj.nuget.g.targets - remote: - httpclient: - bin: - Debug: - net7.0: - files: - - Remote_HttpClient.pdb - - Remote_HttpClient - - Remote_HttpClient.dll - - Remote_HttpClient.runtimeconfig.json - - Newtonsoft.Json.dll - - Remote_HttpClient.deps.json - files: - - Remote_HttpClient.csproj - - Program.cs - obj: - Debug: - net7.0: - files: - - .NETCoreApp,Version=v7.0.AssemblyAttributes.cs - - Remote_HttpClient.csproj.CopyComplete - - Remote_HttpClient.pdb - - Remote_HttpClient.genruntimeconfig.cache - - apphost - - Remote_HttpClient.GlobalUsings.g.cs - - Remote_HttpClient.dll - - Remote_HttpClient.csproj.CoreCompileInputs.cache - - Remote_HttpClient.AssemblyInfo.cs - - Remote_HttpClient.assets.cache - - Remote_HttpClient.csproj.AssemblyReference.cache - - Remote_HttpClient.GeneratedMSBuildEditorConfig.editorconfig - - Remote_HttpClient.csproj.FileListAbsolute.txt - - Remote_HttpClient.AssemblyInfoInputs.cache - ref: - files: - - Remote_HttpClient.dll - refint: - files: - - Remote_HttpClient.dll - files: - - Remote_HttpClient.csproj.nuget.g.targets - - project.nuget.cache - - Remote_HttpClient.csproj.nuget.dgspec.json - - Remote_HttpClient.csproj.nuget.g.props - - project.assets.json - text-to-speech: - httpclient: - bin: - Debug: - net7.0: - files: - - TTS_HttpClient.deps.json - - TTS_HttpClient - - Newtonsoft.Json.dll - - TTS_HttpClient.pdb - - TTS_HttpClient.runtimeconfig.json - - TTS_HttpClient.dll - files: - - TTS_HttpClient.csproj - - Program.cs - obj: - Debug: - net7.0: - files: - - .NETCoreApp,Version=v7.0.AssemblyAttributes.cs - - TTS_HttpClient.csproj.FileListAbsolute.txt - - TTS_HttpClient.csproj.CopyComplete - - TTS_HttpClient.csproj.CoreCompileInputs.cache - - TTS_HttpClient.assets.cache - - apphost - - TTS_HttpClient.GeneratedMSBuildEditorConfig.editorconfig - - TTS_HttpClient.AssemblyInfoInputs.cache - - TTS_HttpClient.pdb - - TTS_HttpClient.csproj.AssemblyReference.cache - - TTS_HttpClient.GlobalUsings.g.cs - - TTS_HttpClient.genruntimeconfig.cache - - TTS_HttpClient.AssemblyInfo.cs - - TTS_HttpClient.dll - ref: - files: - - TTS_HttpClient.dll - refint: - files: - - TTS_HttpClient.dll - files: - - TTS_HttpClient.csproj.nuget.g.targets - - TTS_HttpClient.csproj.nuget.g.props - - project.nuget.cache - - project.assets.json - - TTS_HttpClient.csproj.nuget.dgspec.json - files: - - project_structure.yaml - go: - files: - - go.mod - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - net_http: - files: - - main.go - remote: - net_http: - files: - - main.go - text-to-speech: - net_http: - files: - - main.go - java: - files: - - config.yaml - - pom.xml - - README.md - speech-to-text: - prerecorded: - local: - httpURLConnection: - files: - - Main.java - remote: - okhttp3: - files: - - Main.java - target: - classes: - files: - - Main.class - generated-sources: - annotations: {} - maven-status: - maven-compiler-plugin: - compile: - default-compile: - files: - - inputFiles.lst - - createdFiles.lst - test-classes: {} - text-to-speech: - HttpClient: - files: - - Main.java - okhttp3: - files: - - Main.java - javascript: - files: - - config.yaml - - README.md - - package-lock.json - - package.json - node_modules: - .bin: - files: - - which - async: - files: - - LICENSE - - README.md - - component.json - - package.json - lib: - files: - - async.js - asynckit: - files: - - stream.js - - LICENSE - - index.js - - README.md - - parallel.js - - serialOrdered.js - - package.json - - bench.js - - serial.js - lib: - files: - - abort.js - - terminator.js - - iterate.js - - readable_serial_ordered.js - - readable_parallel.js - - streamify.js - - readable_asynckit.js - - async.js - - state.js - - readable_serial.js - - defer.js - axios: - dist: - browser: - files: - - axios.cjs.map - - axios.cjs - esm: - files: - - axios.js - - axios.min.js.map - - axios.js.map - - axios.min.js - files: - - axios.js - - axios.min.js.map - - axios.js.map - - axios.min.js - node: - files: - - axios.cjs.map - - axios.cjs - files: - - LICENSE - - CHANGELOG.md - - index.d.cts - - index.js - - README.md - - package.json - - MIGRATION_GUIDE.md - - index.d.ts - - SECURITY.md - lib: - adapters: - files: - - fetch.js - - README.md - - adapters.js - - xhr.js - - http.js - cancel: - files: - - CancelToken.js - - isCancel.js - - CanceledError.js - core: - files: - - settle.js - - AxiosError.js - - Axios.js - - InterceptorManager.js - - README.md - - dispatchRequest.js - - buildFullPath.js - - transformData.js - - AxiosHeaders.js - - mergeConfig.js - defaults: - files: - - transitional.js - - index.js - env: - classes: - files: - - FormData.js - files: - - README.md - - data.js - files: - - axios.js - - utils.js - helpers: - files: - - combineURLs.js - - parseProtocol.js - - fromDataURI.js - - deprecatedMethod.js - - buildURL.js - - AxiosTransformStream.js - - null.js - - isURLSameOrigin.js - - isAbsoluteURL.js - - AxiosURLSearchParams.js - - callbackify.js - - isAxiosError.js - - toFormData.js - - cookies.js - - trackStream.js - - validator.js - - composeSignals.js - - ZlibHeaderTransformStream.js - - README.md - - HttpStatusCode.js - - formDataToStream.js - - throttle.js - - formDataToJSON.js - - speedometer.js - - bind.js - - progressEventReducer.js - - readBlob.js - - spread.js - - toURLEncodedForm.js - - resolveConfig.js - - parseHeaders.js - platform: - browser: - classes: - files: - - URLSearchParams.js - - Blob.js - - FormData.js - files: - - index.js - common: - files: - - utils.js - files: - - index.js - node: - classes: - files: - - URLSearchParams.js - - FormData.js - files: - - index.js - buffer-alloc: - files: - - index.js - - readme.md - - package.json - buffer-alloc-unsafe: - files: - - index.js - - readme.md - - package.json - buffer-fill: - files: - - index.js - - readme.md - - package.json - buffer-from: - files: - - LICENSE - - index.js - - readme.md - - package.json - combined-stream: - files: - - License - - Readme.md - - yarn.lock - - package.json - lib: - files: - - combined_stream.js - core-util-is: - files: - - LICENSE - - README.md - - package.json - lib: - files: - - util.js - data-uri-to-buffer: - dist: - files: - - index.js - - index.js.map - - index.d.ts - files: - - README.md - - package.json - src: - files: - - index.ts - debug: - files: - - .npmignore - - LICENSE - - CHANGELOG.md - - Makefile - - .eslintrc - - README.md - - component.json - - node.js - - package.json - - karma.conf.js - - .coveralls.yml - - .travis.yml - src: - files: - - index.js - - node.js - - browser.js - - inspector-log.js - - debug.js - delayed-stream: - files: - - .npmignore - - License - - Makefile - - Readme.md - - package.json - lib: - files: - - delayed_stream.js - fetch-blob: - files: - - LICENSE - - from.d.ts - - file.d.ts - - index.js - - README.md - - package.json - - from.js - - file.js - - index.d.ts - - streams.cjs - files: - - .package-lock.json - fluent-ffmpeg: - .vscode: - files: - - settings.json - OLD: - files: - - README.md - coverage: - files: - - lcov.info - lcov-report: - files: - - index.html - - block-navigation.js - - prettify.js - - regexp.ts.html - - formatting.js.html - - favicon.png - - prettify.css - - sorter.js - - formatting.ts.html - - regexp.js.html - - base.css - - sort-arrow-sprite.png - src: - files: - - command.ts.html - - index.html - - input.ts.html - - process.ts.html - - capabilities.ts.html - - output.ts.html - - main.ts.html - utils: - files: - - platform.ts.html - - index.html - - line-buffer.ts.html - - filters.ts.html - - data-types.ts.html - - regexp.ts.html - - parsing.ts.html - - formatting.ts.html - tests: - acceptance: - files: - - index.html - - dummy.ts.html - helpers: - files: - - index.html - - async.ts.html - - spawn-stub.ts.html - - streams.ts.html - integration: - files: - - index.html - - dummy.ts.html - tmp: - files: - - coverage-1066251-1700211761417-3.json - - coverage-1066251-1700211761217-8.json - - coverage-1066251-1700211761185-1.json - - coverage-1066251-1700211761384-7.json - - coverage-1066251-1700211761265-6.json - - coverage-1066251-1700211761288-9.json - - coverage-1066251-1700211761265-5.json - - coverage-1066251-1700211761296-11.json - - coverage-1066251-1700211761247-2.json - - coverage-1066251-1700211761468-0.json - - coverage-1066251-1700211761301-10.json - - coverage-1066251-1700211761416-4.json - doc: - files: - - options_audio.js.html - - capabilities.js.html - - video.js.html - - processor.js.html - - options_custom.js.html - - misc.js.html - - fluent-ffmpeg.js.html - - index.html - - utils.js.html - - global.html - - FfmpegCommand.html - - custom.js.html - - options_videosize.js.html - - options_output.js.html - - options_video.js.html - - options_misc.js.html - - audio.js.html - - videosize.js.html - - inputs.js.html - - recipes.js.html - - ffprobe.js.html - - options_inputs.js.html - - output.js.html - scripts: - files: - - linenumber.js - prettify: - files: - - lang-css.js - - prettify.js - - Apache-License-2.0.txt - styles: - files: - - jsdoc-default.css - - prettify-tomorrow.css - - prettify-jsdoc.css - files: - - LICENSE - - Makefile - - index.js - - README.md - - package.json - lib: - files: - - fluent-ffmpeg.js - - processor.js - - ffprobe.js - - capabilities.js - - utils.js - - recipes.js - options: - files: - - videosize.js - - misc.js - - custom.js - - audio.js - - output.js - - video.js - - inputs.js - presets: - files: - - divx.js - - podcast.js - - flashvideo.js - tools: - files: - - jsdoc-aliases.js - - jsdoc-conf.json - jsdoc-template: - files: - - README.md - - publish.js - static: - scripts: - files: - - linenumber.js - prettify: - files: - - lang-css.js - - prettify.js - - Apache-License-2.0.txt - styles: - files: - - jsdoc-default.css - - prettify-tomorrow.css - - prettify-jsdoc.css - tmpl: - files: - - layout.tmpl - - mainpage.tmpl - - details.tmpl - - container.tmpl - - tutorial.tmpl - - method.tmpl - - type.tmpl - - aliases.tmpl - - returns.tmpl - - source.tmpl - - members.tmpl - - exceptions.tmpl - - params.tmpl - - example.tmpl - - properties.tmpl - - examples.tmpl - follow-redirects: - files: - - LICENSE - - https.js - - index.js - - README.md - - package.json - - http.js - - debug.js - form-data: - files: - - License - - Readme.md - - README.md.bak - - package.json - - index.d.ts - lib: - files: - - populate.js - - form_data.js - - browser.js - formdata-polyfill: - files: - - esm.min.js - - LICENSE - - esm.min.d.ts - - README.md - - package.json - - formdata-to-blob.js - - FormData.js - - formdata.min.js - inherits: - files: - - LICENSE - - inherits_browser.js - - README.md - - package.json - - inherits.js - isarray: - build: - files: - - build.js - files: - - index.js - - README.md - - component.json - - package.json - isexe: - files: - - .npmignore - - LICENSE - - index.js - - README.md - - package.json - - windows.js - - mode.js - test: - files: - - basic.js - mime-db: - files: - - db.json - - LICENSE - - HISTORY.md - - index.js - - README.md - - package.json - mime-types: - files: - - LICENSE - - HISTORY.md - - index.js - - README.md - - package.json - ms: - files: - - license.md - - index.js - - readme.md - - package.json - node-domexception: - .history: - files: - - package_20210527204621.json - - index_20210527212731.js - - index_20210527214700.js - - index_20210527214654.js - - package_20210527204913.json - - package_20210527203825.json - - package_20210527204925.json - - README_20210527213345.md - - index_20210527213843.js - - package_20210527205145.json - - index_20210527213822.js - - index_20210527211208.js - - index_20210527214034.js - - test_20210527205957.js - - index_20210527204756.js - - index_20210527211248.js - - README_20210527213411.md - - index_20210527213852.js - - index_20210527204833.js - - package_20210527203733.json - - index_20210527204259.js - - test_20210527205603.js - - README_20210527214323.md - - README_20210527214408.md - - index_20210527213910.js - - README_20210527213803.md - - test_20210527210021.js - - index_20210527212746.js - - index_20210527213022.js - - README_20210527203617.md - - index_20210527212722.js - - index_20210527203842.js - - index_20210527214643.js - - package_20210527205156.json - - README_20210527212714.md - - index_20210527203947.js - - index_20210527212900.js - - index_20210527204418.js - files: - - LICENSE - - index.js - - README.md - - package.json - node-fetch: - '@types': - files: - - index.d.ts - files: - - LICENSE.md - - README.md - - package.json - src: - errors: - files: - - fetch-error.js - - abort-error.js - - base.js - files: - - response.js - - request.js - - index.js - - body.js - - headers.js - utils: - files: - - is.js - - get-search.js - - referrer.js - - is-redirect.js - - multipart-parser.js - proxy-from-env: - files: - - test.js - - LICENSE - - .eslintrc - - index.js - - README.md - - package.json - - .travis.yml - readable-stream: - files: - - .npmignore - - LICENSE - - README.md - - passthrough.js - - readable.js - - package.json - - writable.js - - float.patch - - transform.js - - duplex.js - lib: - files: - - _stream_passthrough.js - - _stream_transform.js - - _stream_duplex.js - - _stream_readable.js - - _stream_writable.js - stream-parser: - files: - - .npmignore - - LICENSE - - History.md - - index.js - - README.md - - package.json - - .travis.yml - test: - files: - - writable.js - - transform.js - string_decoder: - files: - - .npmignore - - LICENSE - - index.js - - README.md - - package.json - wav: - examples: - files: - - wavinfo.js - - wav123.js - files: - - LICENSE - - History.md - - index.js - - README.md - - appveyor.yml - - package.json - - .travis.yml - lib: - files: - - file-writer.js - - reader.js - - writer.js - test: - files: - - reader.js - fixtures: - files: - - M1F1-float64-AFsp.wav - - gameover-rifx.wav - - 1up.wav - - M1F1-float32-AFsp.wav - - gameover.wav - web-streams-polyfill: - dist: - files: - - ponyfill.mjs.map - - polyfill.es2018.mjs.map - - polyfill.es6.min.js.map - - ponyfill.es2018.mjs.map - - polyfill.es6.min.js - - polyfill.min.js.map - - ponyfill.es2018.js.map - - ponyfill.es2018.mjs - - polyfill.js.map - - polyfill.es6.mjs.map - - polyfill.es6.js.map - - polyfill.min.js - - polyfill.es2018.min.js.map - - polyfill.es6.mjs - - ponyfill.mjs - - polyfill.es6.js - - polyfill.js - - ponyfill.es6.js.map - - ponyfill.es6.mjs - - polyfill.es2018.min.js - - ponyfill.es2018.js - - ponyfill.es6.js - - polyfill.mjs - - polyfill.es2018.js.map - - ponyfill.es6.mjs.map - - polyfill.es2018.js - - polyfill.es2018.mjs - - polyfill.mjs.map - - ponyfill.js - - ponyfill.js.map - types: - files: - - ponyfill.d.ts - - tsdoc-metadata.json - - polyfill.d.ts - ts3.6: - files: - - ponyfill.d.ts - - polyfill.d.ts - es2018: - files: - - package.json - es6: - files: - - package.json - files: - - LICENSE - - README.md - - package.json - ponyfill: - es2018: - files: - - package.json - es6: - files: - - package.json - files: - - package.json - which: - bin: - files: - - which - files: - - LICENSE - - CHANGELOG.md - - README.md - - which.js - - package.json - ws: - files: - - LICENSE - - wrapper.mjs - - index.js - - README.md - - package.json - - browser.js - lib: - files: - - constants.js - - websocket-server.js - - stream.js - - event-target.js - - permessage-deflate.js - - receiver.js - - sender.js - - subprotocol.js - - limiter.js - - websocket.js - - validation.js - - buffer-util.js - - extension.js - speech-to-text: - prerecorded: - local: - axios: - files: - - index.js - fetch: - files: - - index.js - https: - files: - - index.js - node-fetch: - files: - - index.mjs - remote: - axios: - files: - - index.js - fetch: - files: - - index.js - streaming: - remote: - axios: - files: - - index.js - text-to-speech: - axios: - files: - - index.js - fetch: - files: - - index.js - https: - files: - - index.js - node-fetch: - files: - - index.mjs - php: - files: - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - curl: - files: - - index.php - remote: - curl: - files: - - index.php - text-to-speech: - curl: - files: - - index.php - python: - files: - - requirements.txt - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - http-client: - files: - - main.py - requests: - files: - - main.py - remote: - http-client: - files: - - main.py - requests: - files: - - main.py - streaming: - asyncio: - files: - - main.py - threading: - files: - - main.py - text-to-speech: - http-client: - files: - - main.py - requests: - files: - - main.py - ruby: - files: - - config.yaml - - README.md - - Gemfile - - Gemfile.lock - speech-to-text: - prerecorded: - local: - httparty: - files: - - main.rb - net-http: - files: - - main.rb - remote: - httparty: - files: - - main.rb - net-http: - files: - - main.rb - text-to-speech: - httparty: - files: - - main.rb - net-http: - files: - - main.rb - rust: - files: - - Cargo.toml - - config.yaml - - README.md - speech-to-text: - remote: - files: - - main.rs - text-to-speech: - reqwest: - files: - - main.rs - swift: - files: - - config.yaml - - README.md - speech-to-text: - prerecorded: - local: - urlsession: - files: - - main.swift - remote: - urlsession: - files: - - main.swift - text-to-speech: - urlsession: - files: - - main.swift diff --git a/scripts/generate_descriptions.py b/scripts/generate_descriptions.py index b89c36e..19384c4 100644 --- a/scripts/generate_descriptions.py +++ b/scripts/generate_descriptions.py @@ -1,10 +1,20 @@ import os from openai import OpenAI - -client = OpenAI(api_key='') +from dotenv import load_dotenv import re +import yaml + +load_dotenv() + +API_KEY = os.getenv("OPENAI_API_KEY") + +client = OpenAI(api_key= +API_KEY) + -# Set your OpenAI API key +def read_yaml(file_path): + with open(file_path, 'r') as file: + return yaml.safe_load(file) def read_markdown_file(file_path): with open(file_path, 'r') as file: @@ -22,9 +32,6 @@ def generate_title_and_description(code_sample, relative_path): f"1. **Title:** title here\n" f" **Code Sample:** filename here\n\n" f" **Description:** description here\n\n" - f"2. **Title:** title here\n" - f" **Code Sample:** filename here\n\n" - f" **Description:** description here\n\n" f"## Text-to-Speech Conversion Using Deepgram API\n\n" f"3. **Title:** title here\n" f" **Code Sample:** filename here\n\n" @@ -33,17 +40,15 @@ def generate_title_and_description(code_sample, relative_path): f"Code Sample: {relative_path}\n\n{code_sample}" ) - response = client.chat.completions.create( - model="gpt-4", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": prompt} - ], - max_tokens=1500, - n=1, - stop=None, - temperature=0.5 - ) + response = client.chat.completions.create(model="gpt-4", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": prompt} + ], + max_tokens=1500, + n=1, + stop=None, + temperature=0.5) return response.choices[0].message.content.strip() @@ -70,21 +75,25 @@ def process_markdown_file(file_path): write_markdown_file(file_path, content) def main(): - project_root = os.getcwd() - documentation_dir = os.path.join(project_root, 'documentation') + script_dir = os.path.dirname(os.path.abspath(__file__)) + update_languages_path = os.path.join(script_dir, '../documentation/update_languages.yaml') + documentation_path = os.path.join(script_dir, '../documentation') - updated_files_path = os.path.join(project_root, 'updated_files.txt') - if not os.path.exists(updated_files_path): - print("No files to process.") + update_config = read_yaml(update_languages_path) + if not update_config: + print("Failed to read update_languages.yaml") return - with open(updated_files_path, 'r') as file: - updated_files = [line.strip() for line in file] - - for file_path in updated_files: - if file_path.endswith('-readme.md'): - process_markdown_file(file_path) - print(f"Processed {file_path}") + languages_to_update = update_config.get('languages', []) + for language_path in languages_to_update: + if not language_path.startswith('#'): + language = os.path.basename(language_path.strip()) + markdown_file = os.path.join(documentation_path, f"{language}-readme.md") + if os.path.exists(markdown_file): + print(f"Processing {markdown_file}") + process_markdown_file(markdown_file) + else: + print(f"Markdown file not found: {markdown_file}") if __name__ == "__main__": main() diff --git a/scripts/generate_directory_structure.py b/scripts/generate_directory_structure.py deleted file mode 100644 index 3c15619..0000000 --- a/scripts/generate_directory_structure.py +++ /dev/null @@ -1,38 +0,0 @@ -import os -import yaml - -def generate_directory_structure(root_dir, base_dir_name): - directory_dict = {base_dir_name: {}} - - for root, dirs, files in os.walk(root_dir): - # Skip directories above the base_dir_name - if base_dir_name not in root: - continue - - path = root.split(os.sep) - # Find the index of the base_dir_name in the path - base_index = path.index(base_dir_name) - # Create a sub-path starting from the base_dir_name - sub_path = path[base_index:] - parent = directory_dict[base_dir_name] - for folder in sub_path[1:]: # Skip the base_dir_name itself - parent = parent.setdefault(folder, {}) - for file in files: - parent.setdefault('files', []).append(file) - - return directory_dict - -def write_yaml_file(data, output_file): - with open(output_file, 'w') as file: - yaml.dump(data, file, default_flow_style=False) - -def main(): - project_root = os.getcwd() - languages_dir = os.path.join(project_root, 'languages') - output_file = os.path.join(languages_dir, 'project_structure.yaml') - - directory_structure = generate_directory_structure(project_root, 'languages') - write_yaml_file({'code-samples': directory_structure}, output_file) - -if __name__ == "__main__": - main() diff --git a/scripts/generate_docs.py b/scripts/generate_docs.py index 6b814c7..9729a6a 100644 --- a/scripts/generate_docs.py +++ b/scripts/generate_docs.py @@ -1,139 +1,126 @@ import os import yaml -import fnmatch +from pathlib import Path import subprocess -from deepdiff import DeepDiff -def load_yaml_file(file_path): - if not os.path.exists(file_path): - return {} - with open(file_path, 'r') as file: - return yaml.safe_load(file) - -def generate_directory_structure(root_dir, base_dir_name): - directory_dict = {base_dir_name: {}} - - for root, dirs, files in os.walk(root_dir): - if base_dir_name not in root: - continue - - path = root.split(os.sep) - base_index = path.index(base_dir_name) - sub_path = path[base_index:] - parent = directory_dict[base_dir_name] - for folder in sub_path[1:]: - parent = parent.setdefault(folder, {}) - for file in files: - parent.setdefault('files', []).append(file) - - return directory_dict - -def write_yaml_file(data, output_file): - with open(output_file, 'w') as file: - yaml.dump(data, file, default_flow_style=False) - -def get_target_files(config_path): - config = load_yaml_file(config_path) - if isinstance(config, dict): - return config.get('target_files', []) - else: - print(f"Error: Config file at {config_path} is not formatted correctly.") - return [] - -def generate_readme_for_language(language_dir, target_patterns, documentation_dir, updated_files): - readme_path = os.path.join(documentation_dir, f"{os.path.basename(language_dir)}-readme.md") - original_content = None - if os.path.exists(readme_path): - with open(readme_path, 'r') as readme_file: - original_content = readme_file.read() - - new_content = [] - for root, _, files in os.walk(language_dir): - for file in files: - if file == 'project_structure.yaml': - continue # Skip the project_structure.yaml file - if any(fnmatch.fnmatch(file, pattern) for pattern in target_patterns): - file_path = os.path.join(root, file) - relative_path = os.path.relpath(file_path, language_dir) - new_content.append(f"### {relative_path}\n\n") - new_content.append("```{}\n".format(os.path.basename(language_dir))) - with open(file_path, 'r') as code_file: - new_content.append(code_file.read()) - new_content.append("\n```\n\n") - - new_content_str = ''.join(new_content) - - if original_content != new_content_str or not os.path.exists(readme_path): # Include newly created files +def read_yaml(file_path): + try: + with open(file_path, 'r') as file: + print(f"Reading YAML file: {file_path}") + return yaml.safe_load(file) + except Exception as e: + print(f"Error reading YAML file {file_path}: {e}") + return None + +def write_yaml(file_path, data): + try: + with open(file_path, 'w') as file: + yaml.dump(data, file, default_flow_style=False) + except Exception as e: + print(f"Error writing YAML file {file_path}: {e}") + +def write_to_readme(language, content, documentation_path): + try: + readme_path = os.path.join(documentation_path, f'{language}-readme.md') + print(f"Writing content to: {readme_path}") with open(readme_path, 'w') as readme_file: - readme_file.write(new_content_str) - updated_files.append(readme_path) - -def main(): - project_root = os.getcwd() - languages_dir = os.path.join(project_root, 'languages') - documentation_dir = os.path.join(project_root, 'documentation') - os.makedirs(documentation_dir, exist_ok=True) - old_project_structure_path = os.path.join(languages_dir, 'project_structure.yaml') - - # Load the old project structure - old_project_structure = load_yaml_file(old_project_structure_path) - - # Generate the new project structure - new_directory_structure = generate_directory_structure(project_root, 'languages') - new_project_structure = {'code-samples': new_directory_structure} - - # Compare the old and new project structures - diff = DeepDiff(old_project_structure, new_project_structure, ignore_order=True) - updated_languages = [] - - if diff: - # Update the project_structure.yaml file - write_yaml_file(new_project_structure, old_project_structure_path) - - # Identify updated or newly added languages - if 'dictionary_item_added' in diff or 'values_changed' in diff: - for item in diff.get('dictionary_item_added', []): - path_parts = item.split('[') - if len(path_parts) > 2 and path_parts[1].strip(']') == "'languages'": - updated_languages.append(path_parts[2].strip("]'")) - for item in diff.get('values_changed', []): - path_parts = item.split('[') - if len(path_parts) > 2 and path_parts[1].strip(']') == "'languages'": - updated_languages.append(path_parts[2].strip("]'")) - - # Track updated files - updated_files = [] - - # Generate the readme files based on the new project structure and config files - for language in os.listdir(languages_dir): - language_dir = os.path.join(languages_dir, language) - if os.path.isdir(language_dir): - config_path = os.path.join(language_dir, 'config.yaml') - if os.path.exists(config_path): - target_patterns = get_target_files(config_path) - if target_patterns: - generate_readme_for_language(language_dir, target_patterns, documentation_dir, updated_files) + readme_file.write(content) + except Exception as e: + print(f"Error writing to {readme_path}: {e}") + +def scrape_code_from_files(language_path, target_files, language): + content = "" + for root, _, files in os.walk(language_path): + for target in target_files: + for file_name in files: + if Path(file_name).match(target): + file_path = os.path.join(root, file_name) + relative_path = os.path.relpath(file_path, language_path) + print(f"Scraping content from: {file_path}") + try: + with open(file_path, 'r') as code_file: + file_content = code_file.read() + content += f"### {relative_path}\n\n" + content += f"```{language}\n{file_content}\n```\n\n" + except Exception as e: + print(f"Error reading file {file_path}: {e}") + return content + +def print_directory_tree(startpath): + for root, dirs, files in os.walk(startpath): + level = root.replace(startpath, '').count(os.sep) + indent = ' ' * 4 * (level) + print(f"{indent}{os.path.basename(root)}/") + subindent = ' ' * 4 * (level + 1) + for f in files: + print(f"{subindent}{f}") + +def process_language(language_path, documentation_path, language): + print(f"Directory structure for {language_path}:") + print_directory_tree(language_path) + + config_path = os.path.join(language_path, 'config.yaml') + if os.path.exists(config_path): + config = read_yaml(config_path) + if config: + target_files = config.get('target_files', []) + if target_files: + content = scrape_code_from_files(language_path, target_files, language) + if content: + write_to_readme(language, content, documentation_path) else: - print(f"Warning: No target patterns found for {language}.") + print(f"No content scraped for language: {language}") else: - print(f"Warning: config.yaml not found for {language}. Skipping.") + print(f"No target files specified in config.yaml for {language_path}") else: - print(f"Skipping non-directory item: {language}") + print(f"Failed to read config.yaml in {language_path}") + else: + print(f"config.yaml not found in {language_path}") + +def reset_update_languages(update_languages_path): + with open(update_languages_path, 'r') as file: + lines = file.readlines() + + with open(update_languages_path, 'w') as file: + for line in lines: + stripped_line = line.lstrip() + if stripped_line.startswith('- '): + indent = line[:len(line) - len(stripped_line)] + file.write(f'{indent}# - {stripped_line[2:].strip()}\n') + else: + file.write(line) - # Write the list of updated files to a temporary file - updated_files_path = os.path.join(project_root, 'updated_files.txt') - with open(updated_files_path, 'w') as file: - for updated_file in updated_files: - file.write(updated_file + '\n') + print(f"Reset {update_languages_path} with all languages commented out.") - # Run the generate_descriptions.py script if there are updated files - if updated_files: - print("Running generate_descriptions.py to update descriptions...") - subprocess.run(['python', 'scripts/generate_descriptions.py']) +def main(): + script_dir = os.path.dirname(os.path.abspath(__file__)) + base_path = os.path.join(script_dir, '../languages') + documentation_path = os.path.join(script_dir, '../documentation') + update_languages_path = os.path.join(documentation_path, 'update_languages.yaml') + + update_config = read_yaml(update_languages_path) + if not update_config: + print("Failed to read update_languages.yaml or it is empty") + return + + languages_to_update = update_config.get('languages', []) + if not languages_to_update: + print("No languages to update") + return + + for language_path in languages_to_update: + if not language_path.startswith('#'): + full_language_path = os.path.join(base_path, language_path.strip()) + language = os.path.basename(language_path.strip()) + print(f"Processing language path: {full_language_path}") + process_language(full_language_path, documentation_path, language) + + # Call the generate_descriptions.py script + generate_descriptions_path = os.path.join(script_dir, 'generate_descriptions.py') + subprocess.run(['python', generate_descriptions_path]) + + # Reset update_languages.yaml + reset_update_languages(update_languages_path) - # Clear the updated_files.txt after processing - with open(updated_files_path, 'w') as file: - file.write('') - if __name__ == "__main__": main() diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..07e9b53 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,3 @@ +openai +PyYAML +python-dotenv \ No newline at end of file diff --git a/updated_files.txt b/updated_files.txt deleted file mode 100644 index 3570baf..0000000 --- a/updated_files.txt +++ /dev/null @@ -1,11 +0,0 @@ -/Users/sandrarodgers/Misc/code-samples/documentation/go-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/python-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/rust-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/java-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/php-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/cpp-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/swift-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/csharp-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/javascript-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/c-readme.md -/Users/sandrarodgers/Misc/code-samples/documentation/ruby-readme.md