Skip to content

Instantly share code, notes, and snippets.

@davesnowdon
davesnowdon / chatgpt-cpp-audio2.cpp
Created December 31, 2022 12:17
please update the code to check for errors in the snd_pcm_hw_params functions
#include <alsa/asoundlib.h>
#include <iostream>
int main() {
// Open the default PCM device
snd_pcm_t *handle;
int error = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0);
if (error < 0) {
std::cerr << "Error opening PCM device: " << snd_strerror(error) << std::endl;
return 1;
@davesnowdon
davesnowdon / chatgpt-cpp-audio1.cpp
Created December 31, 2022 12:16
Can you help me write a C++ program that reads blocks of audio data from the microphone using the ALSA driver?
#include <alsa/asoundlib.h>
#include <iostream>
int main() {
// Open the default PCM device
snd_pcm_t *handle;
int error = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0);
if (error < 0) {
std::cerr << "Error opening PCM device: " << snd_strerror(error) << std::endl;
return 1;
@davesnowdon
davesnowdon / chatgpt-linux-read-audio.cpp
Created December 29, 2022 19:32
ChatGPT: Write a C++ program for Linux which reads audio using the ALSA driver and encodes it using FLAC
#include <alsa/asoundlib.h>
#include <flac++/encoder.h>
#include <cstdio>
#include <cstring>
constexpr int kSampleRate = 44100; // Sample rate in Hz
constexpr int kNumChannels = 2; // Number of channels
constexpr int kBufferSize = 4096; // Size of the audio buffer
@davesnowdon
davesnowdon / chatgpt-audio-stream.go
Last active November 27, 2024 10:01
ChatGPT: Write a go program that sends real-time audio using gRPC streaming
package main
import (
"context"
"fmt"
"io"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@davesnowdon
davesnowdon / chatgpt-flutter-address-form.dart
Created December 29, 2022 19:30
ChatGPT: write a simple flutter application that displays a form requesting a person's name and address and stores the result in a local database
import 'package:flutter/material.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
var opts []grpc.DialOption
serverAddr := "localhost:50051"
conn, err := grpc.Dial(*serverAddr, opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
defer conn.Close()
client := pb.NewTheSocialRobotClient(conn)
type TheSocialRobotClient interface {
EventStream(ctx context.Context, opts ...grpc.CallOption) (TheSocialRobot_EventStreamClient, error)
}
grpcServer.Serve(lis)
pb.RegisterTheSocialRobotServer(grpcServer, new(theSocialRobotServer))
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)