-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Record and send audio via Chrome microphone #1996
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0ac7d03
audio recording basics
namanagar 03f1fe1
minor ui fixes
namanagar ec5c7dd
refactor
namanagar 45cc045
fix logic
namanagar 59f0e59
Merge branch 'main' into naman/playground-microphone
namanagar c5fe7f6
audio controls + backend mime type
namanagar 714fa29
Merge branch 'main' into naman/playground-microphone
namanagar fa1e217
cleanup + hook up backend mimetype
namanagar ce075d7
lint fixes
namanagar 9d48268
add todo
namanagar def5310
cleaner
namanagar 5c31751
more cleanup
namanagar a724ea8
tiny copy edit
namanagar 3cb2f2d
Merge branch 'main' into naman/playground-microphone
namanagar 96afbbf
small controls update
namanagar 8aa06fd
iconoir -> lucide, one bug with invalid files
namanagar 9c3bba3
remove stringtype changes
namanagar a075b30
Merge branch 'main' into naman/playground-microphone
namanagar 5406b4d
remove string + mimetype on frontend
namanagar bd82d05
Merge branch 'main' into naman/playground-microphone
namanagar dc00c6b
address comments
namanagar ca005e1
Merge branch 'main' into naman/playground-microphone
namanagar a11d543
fix compile breaks
RohinBhargava 8837793
Merge branch 'main' into naman/playground-microphone
namanagar 16f1a5d
prettier
namanagar f93ad11
Merge branch 'naman/playground-microphone' of github.com:fern-api/fer…
namanagar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...enerated/api/resources/api/resources/v1/resources/read/resources/type/types/Base64Type.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...ated/api/resources/api/resources/v1/resources/register/resources/type/types/Base64Type.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
packages/fern-docs/ui/src/playground/form/PlaygroundAudioControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { FernButton, FernButtonGroup } from "@fern-docs/components"; | ||
import { Download, Octagon, Play } from "lucide-react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
interface PlaygroundAudioControlsProps { | ||
audioUrl: string | null; | ||
fileName?: string; | ||
} | ||
|
||
export function PlaygroundAudioControls({ | ||
audioUrl, | ||
fileName = "recording.webm", | ||
}: PlaygroundAudioControlsProps) { | ||
const [isPlaying, setIsPlaying] = useState(false); | ||
const [currentTime, setCurrentTime] = useState(0); | ||
const [duration, setDuration] = useState(0); | ||
const [isLoaded, setIsLoaded] = useState(false); | ||
const audioRef = useRef<HTMLAudioElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (audioRef.current) { | ||
audioRef.current.onended = () => setIsPlaying(false); | ||
audioRef.current.onloadedmetadata = () => { | ||
const audioDuration = audioRef.current?.duration; | ||
if (audioDuration && !isNaN(audioDuration) && isFinite(audioDuration)) { | ||
setDuration(Math.round(audioDuration)); | ||
setIsLoaded(true); | ||
} | ||
}; | ||
audioRef.current.ontimeupdate = () => { | ||
const currentTime = audioRef.current?.currentTime; | ||
if (currentTime && !isNaN(currentTime) && isFinite(currentTime)) { | ||
setCurrentTime(Math.round(currentTime)); | ||
} | ||
}; | ||
} | ||
}, []); | ||
|
||
const formatTime = (seconds: number) => { | ||
const mins = Math.floor(seconds / 60) | ||
.toString() | ||
.padStart(2, "0"); | ||
const secs = (seconds % 60).toString().padStart(2, "0"); | ||
return `${mins}:${secs}`; | ||
}; | ||
|
||
const handlePlayPause = async () => { | ||
if (!audioRef.current || !audioUrl) return; | ||
|
||
if (isPlaying) { | ||
audioRef.current.pause(); | ||
audioRef.current.currentTime = 0; | ||
setCurrentTime(0); | ||
} else { | ||
await audioRef.current.play(); | ||
} | ||
setIsPlaying(!isPlaying); | ||
}; | ||
|
||
const handleDownload = () => { | ||
if (!audioUrl) return; | ||
const a = document.createElement("a"); | ||
a.href = audioUrl; | ||
a.download = fileName; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
}; | ||
|
||
if (!audioUrl) return null; | ||
|
||
return ( | ||
<div className="flex items-center gap-2"> | ||
<audio ref={audioRef} src={audioUrl} preload="metadata" /> | ||
{isLoaded && ( | ||
<span className="font-mono text-xs"> | ||
{`${formatTime(currentTime)}/${formatTime(duration)}`} | ||
</span> | ||
)} | ||
<FernButtonGroup> | ||
<FernButton | ||
icon={isPlaying ? <Octagon /> : <Play />} | ||
onClick={handlePlayPause} | ||
size="small" | ||
variant="minimal" | ||
disabled={!audioUrl} | ||
/> | ||
<FernButton | ||
icon={<Download />} | ||
onClick={handleDownload} | ||
size="small" | ||
variant="minimal" | ||
disabled={!audioUrl} | ||
/> | ||
</FernButtonGroup> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny package that helps w/ the blob data from the media recorder api — without this, the
<audio>
element after recording has incorrect metadata (duration: Infinity) which messes with the playback