Module: PodcastBuddy

Defined in:
lib/podcast_buddy.rb,
lib/podcast_buddy/version.rb,
lib/podcast_buddy/pod_signal.rb,
lib/podcast_buddy/system_dependency.rb

Defined Under Namespace

Classes: Error, PodSignal, SystemDependency

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.add_to_topics(topics) ⇒ Object



114
115
116
117
# File 'lib/podcast_buddy.rb', line 114

def self.add_to_topics(topics)
  File.open(topics_log_file, "a") { |f| f.puts topics }
  current_topics << topics
end

.answer_audio_file_pathObject



123
124
125
# File 'lib/podcast_buddy.rb', line 123

def self.answer_audio_file_path
  @answer_audio_file_path ||= "response.mp3"
end

.answer_audio_file_path=(file_path) ⇒ Object



119
120
121
# File 'lib/podcast_buddy.rb', line 119

def self.answer_audio_file_path=(file_path)
  @answer_audio_file_path = file_path
end

.current_summaryObject



100
101
102
# File 'lib/podcast_buddy.rb', line 100

def self.current_summary
  @current_summary ||= File.exist?(summary_log_file) ? File.read(summary_log_file) : ""
end

.current_topicsObject



110
111
112
# File 'lib/podcast_buddy.rb', line 110

def self.current_topics
  @current_topics ||= File.exist?(topics_log_file) ? File.read(topics_log_file) : ""
end

.current_transcriptObject



91
92
93
# File 'lib/podcast_buddy.rb', line 91

def self.current_transcript
  @current_transcript ||= File.exist?(transcript_file) ? File.read(transcript_file) : ""
end

.loggerObject



31
32
33
# File 'lib/podcast_buddy.rb', line 31

def self.logger
  @logger ||= Logger.new($stdout, level: Logger::DEBUG)
end

.logger=(logger) ⇒ Object



35
36
37
# File 'lib/podcast_buddy.rb', line 35

def self.logger=(logger)
  @logger = logger
end

.openai_clientObject

Raises:



145
146
147
148
149
# File 'lib/podcast_buddy.rb', line 145

def self.openai_client
  raise Error, "Please set an OPENAI_ACCESS_TOKEN environment variable." if ENV["OPENAI_ACCESS_TOKEN"].to_s.strip.squeeze.empty?

  @openai_client ||= OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"], log_errors: true)
end

.openai_client=(client) ⇒ Object



141
142
143
# File 'lib/podcast_buddy.rb', line 141

def self.openai_client=(client)
  @openai_client = client
end

.rootObject



19
20
21
# File 'lib/podcast_buddy.rb', line 19

def self.root
  Dir.pwd
end

.sessionObject



27
28
29
# File 'lib/podcast_buddy.rb', line 27

def self.session
  @session ||= "#{root}/tmp"
end

.session=(name) ⇒ Object



23
24
25
# File 'lib/podcast_buddy.rb', line 23

def self.session=(name)
  @session = "#{root}/tmp/#{name}"
end

.setupObject



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/podcast_buddy.rb', line 127

def self.setup
  gemfile do
    source "https://rubygems.org"
    gem "ruby-openai"
  end

  require "openai"
  logger.info "Gems installed and loaded!"
  SystemDependency.auto_install!(:git)
  SystemDependency.auto_install!(:sdl2)
  SystemDependency.auto_install!(:whisper)
  SystemDependency.resolve_whisper_model(whisper_model)
end

.show_notes_fileObject



87
88
89
# File 'lib/podcast_buddy.rb', line 87

def self.show_notes_file
  @show_notes_file ||= "#{session}/show-notes-#{Time.new.strftime("%Y-%m-%d")}.md"
end

.show_notes_file=(file_path) ⇒ Object



83
84
85
# File 'lib/podcast_buddy.rb', line 83

def self.show_notes_file=(file_path)
  @show_notes_file = file_path
end

.summary_log_fileObject



71
72
73
# File 'lib/podcast_buddy.rb', line 71

def self.summary_log_file
  @summary_log_file ||= "#{session}/summary-#{Time.new.strftime("%Y-%m-%d")}.log"
end

.summary_log_file=(log_file_path) ⇒ Object



67
68
69
# File 'lib/podcast_buddy.rb', line 67

def self.summary_log_file=(log_file_path)
  @summary_log_file = log_file_path
end

.topics_log_fileObject



63
64
65
# File 'lib/podcast_buddy.rb', line 63

def self.topics_log_file
  @topics_log_file ||= "#{session}/topics-#{Time.new.strftime("%Y-%m-%d")}.log"
end

.topics_log_file=(log_file_path) ⇒ Object



59
60
61
# File 'lib/podcast_buddy.rb', line 59

def self.topics_log_file=(log_file_path)
  @topics_log_file = log_file_path
end

.transcript_fileObject



79
80
81
# File 'lib/podcast_buddy.rb', line 79

def self.transcript_file
  @transcript_file ||= "#{session}/transcript-#{Time.new.strftime("%Y-%m-%d")}.log"
end

.transcript_file=(file_path) ⇒ Object



75
76
77
# File 'lib/podcast_buddy.rb', line 75

def self.transcript_file=(file_path)
  @transcript_file = file_path
end

.update_summary(text) ⇒ Object



104
105
106
107
108
# File 'lib/podcast_buddy.rb', line 104

def self.update_summary(text)
  @current_summary = text
  File.write(summary_log_file, text)
  @current_summary
end

.update_transcript(text) ⇒ Object



95
96
97
98
# File 'lib/podcast_buddy.rb', line 95

def self.update_transcript(text)
  File.open(transcript_file, "a") { |f| f.puts text }
  current_transcript << text
end

.whisper_commandObject



47
48
49
# File 'lib/podcast_buddy.rb', line 47

def self.whisper_command
  "./whisper.cpp/stream -m ./whisper.cpp/models/ggml-#{PodcastBuddy.whisper_model}.bin -t 4 --step 0 --length 5000 --keep 500 --vad-thold 0.60 --audio-ctx 0 --keep-context -c 1"
end

.whisper_loggerObject



55
56
57
# File 'lib/podcast_buddy.rb', line 55

def self.whisper_logger
  @whisper_logger ||= Logger.new("#{session}/whisper.log", "daily")
end

.whisper_logger=(file_path) ⇒ Object



51
52
53
# File 'lib/podcast_buddy.rb', line 51

def self.whisper_logger=(file_path)
  @whisper_logger ||= Logger.new(file_path, "daily")
end

.whisper_modelObject



43
44
45
# File 'lib/podcast_buddy.rb', line 43

def self.whisper_model
  @whisper_model ||= "small.en"
end

.whisper_model=(model) ⇒ Object



39
40
41
# File 'lib/podcast_buddy.rb', line 39

def self.whisper_model=(model)
  @whisper_model = model
end