Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotberry committed Feb 5, 2024
1 parent 74342ea commit a7e6b2e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy to Raspberry Pi via Tailscale

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Tailscale
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
- name: Deploy to Raspberry Pi
run: |
# Replace with your deployment script
ssh pi@your-tailscale-ip-address 'cd /path/to/your/repo && git pull origin main'
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
Binary file added cache/530e3997e201e0c99a87fa54e5c433f7.mp3
Binary file not shown.
Binary file added cache/70a4d0c2f4c4e8ce5dde5469222f1a39.mp3
Binary file not shown.
23 changes: 23 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use an official Node.js runtime as the base image
FROM node:20

# Set the working directory in the container
WORKDIR /app

# Install alsa-utils
RUN apt-get update && apt-get install -y alsa-utils

# Copy package.json and package-lock.json to the container
COPY package*.json ./

# Install Node.js dependencies
RUN npm install

# Copy your Node.js application code to the container
COPY . .

# Expose port 9099 for the Node.js application
EXPOSE 9099

# Start the Node.js application
CMD [ "node", "index.js" ]
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import http from 'node:http'
import playCachedAudio from './playCachedAudio.js'

import logger from './logger.js'
const server = http.createServer(async (req, res) => {
if (req.method === 'GET' && req.url === '/') {
console.log('GET /')
logger.info('GET /')
logger.info('hello world')
await playCachedAudio('hello world')
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({ hello: 'world' }))
} else if (req.method === 'POST' && req.url === '/') {
console.log('POST /')
logger.info('POST /')
try {
let body = ''
req.on('data', (chunk) => {
body += chunk
})
req.on('end', async () => {
console.log(body)
const { message } = JSON.parse(body)
await playCachedAudio(message)
res.setHeader('Content-Type', 'application/json')
Expand All @@ -34,7 +36,7 @@ const port = process.env.PORT || 9099
const host = '0.0.0.0'

server.listen(port, host, () => {
console.log(`Server listening on ${host}:${port}`)
logger.info(`Server listening on ${host}:${port}`)
});

process.on('uncaughtException', (err) => {
Expand Down
9 changes: 4 additions & 5 deletions playCachedAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ async function playCachedAudio(text, speaker = 'en_us_001') {
let possiblePath = await getCachePath(text + speaker);
if (await exists(possiblePath)) {
logger.info('cache hit');
let buf = await fs.readFile(possiblePath);
await play(buf);
// let buf = await fs.readFile(possiblePath);
await play(possiblePath);
return;
}
else {
logger.info('cache miss');
let buf = await getAudio(text, speaker);
await fs.writeFile (possiblePath, buf);
await play(buf);

await fs.writeFile(possiblePath, buf);
await play(possiblePath);
}

} catch (e) {
Expand Down

0 comments on commit a7e6b2e

Please sign in to comment.